-1

I see this as a very common problem for people trying to parse, but I'm still at a loss for what I need to do:

I have a json, I'm reading it from php webservice response:

{
Name: "Balrog",
Origin: "USA",
Age: "28",
Height: "6`5",
Weight: "252 lbs",
Game: "Street Fighter",
Image: "N/A"
},
{
Name: "Faust",
Origin: "Parts Unknown",
Age: "Unknown",
Height: "9`1",
Weight: "165 lbs",
Game: "Guilty Gear",
Image: "N/A"
},
{
Name: "Hugo",
Origin: "Germany",
Age: "28",
Height: "8`2",
Weight: "440 lbs",
Game: "Final Fight",
Image: "N/A"
}

But when I try to parse I face many problems around declaring the "NSDictionary" area. I know the *results' "objectforkey" needs to be changed, but I have no idea.

listOfFighters = nil;

    NSString* WebServiceURL = @"URL_GOES_HERE";
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{

        // Get the JSON string from our web serivce
        NSDictionary * dictionary = [JSONHelper loadJSONDataFromURL:WebServiceURL];

        dispatch_async(dispatch_get_main_queue(), ^{

            // Get a list of results in the Dictionary
            NSArray *results = [dictionary objectForKey:@"GetAllFightersResult"];
Jenz
  • 8,280
  • 7
  • 44
  • 77
Pogs
  • 3
  • 1

2 Answers2

2

If your posted JSON is correct then try this:

// Get the JSON string from our web service
NSArray * dictionary = [JSONHelper loadJSONDataFromURL:WebServiceURL];

Each index contains a NSDictionary. Hope this helps.. :)

Rashad
  • 11,057
  • 4
  • 45
  • 73
0

The given JSON is not valid. Please read the documentation at http://www.json.org/ and try to validate your JSON via http://jsonlint.com/.

Correct JSON example:

[
   {
       "Name": "Balrog",
       "Origin": "USA"
   },
   {
       "Name": "Faust",
       "Origin": "Parts Unknown"
   }
]



This will give you an NSArray with NSDictionaries containing the Key-Value-Pair "Name" and "Origin".