Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse Json value in iPhone? [duplicate]

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
                }
            }
        },
like image 969
SampathKumar Avatar asked Nov 03 '22 05:11

SampathKumar


1 Answers

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];
like image 110
Fogmeister Avatar answered Nov 14 '22 14:11

Fogmeister