WaqasArshad WaqasArshad - 27 days ago 6
Objective-C Question

Trying to get plist data from server but getting nothing

i am building this app in which i need to get data from server here is my code

NSString *url = [NSString stringWithFormat:@"http://URL/ios/jobsearch.php"];
NSDictionary *dataDict = [[NSDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
OriginalResultArray=[dataDict valueForKey:@"Objects"];
jobResultArray=[[NSMutableArray alloc] init];
[jobResultArray addObjectsFromArray:OriginalResultArray];
NSLog(@"Result is : %@",jobResultArray);


and here is my jobsearch.php

<plist version="1.0">
<dict>
<key>Objects</key>
<array>
<dict>
<key>jobname</key>
<string>asdfasdf111</string>
<key>jobbids</key>
<integer>3</integer>
<key>jobpay</key>
<integer>$30</integer>
<key>jobid</key>
<integer>3</integer>
</dict>
<dict>
<key>jobname</key>
<string>asdfasdf1111111333</string>
<key>jobbids</key>
<integer>1</integer>
<key>jobpay</key>
<integer>$36</integer>
<key>jobid</key>
<integer>5</integer>
</dict>
</array>
</dict>
</plist>


with all this code i am getting noting in return. There are 2 Dict in my php file if you see and every dict have 4 keys in it. if i remove 2 keys from every dict and have only 2 keys so in that case i do get data in my array. but i need all 4 keys with data. Please help. Thanks in Advance.

Answer

The data isn't in right format.

enter image description here

Change

<key>jobpay</key>
<integer>$30</integer>

to

<key>jobpay</key>
<string>$30</string>

Now data is in right format.

enter image description here

Below is the complete data.

<plist version="1.0">
<dict>
    <key>Objects</key>
    <array>
        <dict>
            <key>jobname</key>
            <string>asdfasdf111</string>
            <key>jobbids</key>
            <integer>3</integer>
            <key>jobpay</key>
            <string>$30</string>
            <key>jobid</key>
            <integer>3</integer>
        </dict>
        <dict>
            <key>jobname</key>
            <string>asdfasdf1111111333</string>
            <key>jobbids</key>
            <integer>1</integer>
            <key>jobpay</key>
            <string>$36</string>
            <key>jobid</key>
            <integer>5</integer>
        </dict>
    </array>
</dict>

Final Output:

enter image description here