5

Possible Duplicate:
How to parsing JSON object in iPhone SDK (XCode) using JSON-Framework

I am working in iPhone application, Using JSON framework to parse Json value from Web service, How to get the Json value like 1221, 1278,3456,........... etc. (This value are not constant, it is dynamically change the value automatically, so i didn't know that) Is it possible to do that?

Thanks in Advance

JSON Response for your reference:

  {
        "1221": 
    {
            "type": "product",
            "product_id": 1221,
            "intID": "1",
            "name": "rer Margherita",
            "des": "Tomatensauce, Käse<sup>1</sup>",
            "img": "",
            "isDeal": false,
            "cat": {
                "1": {
                    "price": 4,
                    "pos": 1,
                    "catname": "normal",
                    "extras": false
                },
                "2": {
                    "price": 5.9,
                    "pos": 2,
                    "catname": "groß",
                    "extras": false
                }
            }
        },
        "1278": {
            "type": "product",
            "product_id": 1222,
            "intID": "2",
            "name": "ere Zwirerebeln",
            "des": "er",
            "img": "",
            "isDeal": false,
            "cat": {
                "1": {
                    "price": 2,
                    "pos": 1,
                    "catname": "rer",
                    "extras": true
                },
                "2": {
                    "price": 6.2,
                    "pos": 2,
                    "catname": "mega",
                    "extras": true
                }
            }
        },
Community
  • 1
  • 1
SampathKumar
  • 2,525
  • 8
  • 47
  • 82

1 Answers1

2

Just convert your JSON Data into an object

NSData *jsonData = //response data

NSDictionary *object = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];

Then there is no parsing involved, you just deal with the dictionary. (Or array, etc...)

To get the list you want you can then do...

NSArray *requiredValues = [object allKeys];
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • Why would you first convert your `NSData` object to an `NSString` (ASCII? really?) and then back to `NSData` instead of just using `self` in `JSONObjectWithData:`? I don't see why you'd need a category method for something that is a one-liner anyway. – omz Jan 31 '13 at 09:20
  • I dunno, it's just something I used a while back and it stuck. Good point thoguh. – Fogmeister Jan 31 '13 at 09:31