سؤال

I am in the process of retrieving data via "JSON" from a NSMutableURLRequest. The data comes back and I convert to a dictionary via:

 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:companyData //1
                                                     options:kNilOptions
                                                       error:&e];

The problem I am having is, of the data coming back, when I take it and:

 NSArray* parameterInfo = [json objectForKey:@"parameters"];

The returned data is in the form of the below, which is showing as a NSDictionary but I can't for the life of me, figure out how to convert that to a data I can read. Meaning, the "parameterInfo array" item, how do I read it as an NSDictionary and then able to programmatically use the data.

As you can see from the below, the "KEY" is a dictionary.

I hope this makes sense. Any help is greatly appreciated.

Geo:

 2014-05-14 15:20:26.343 testdata[12052:60b] parameterInfo:  {
key =     {
    "@name" = "Product_Search";
    value =         (
                    {
            "@name" = Heated;
            "@totalCount" = 2;
        },
                    {
            "@name" = Drill;
            "@totalCount" = 2;
        },
                    {
            "@name" = Heat;
            "@totalCount" = 1;
        },
                    {
            "@name" = Sprayer;
            "@totalCount" = 1;
        },
                    {
            "@name" = Paint;
            "@totalCount" = 1;
        },
                    {
            "@name" = 2653;
            "@totalCount" = 2;
        },
                    {
            "@name" = "0884-20";
            "@totalCount" = 1;
        },
                    {
            "@name" = Hand;
            "@totalCount" = 1;
        },
                    {
            "@name" = Vacu;
            "@totalCount" = 1;
        },
                    {
            "@name" = "Drill Driver";
            "@totalCount" = 1;
        },
                    {
            "@name" = Blower;
            "@totalCount" = 3;
        },
                    {
            "@name" = Blow;
            "@totalCount" = 5;
        }
    );
هل كانت مفيدة؟

المحلول 2

How about:

 NSDictionary* parameterInfo = [json objectForKey:@"parameters"];
 NSArray * myParameters = [[parameterInfo objectForKey:@"key"] objectForKey:@"value"];

json is a dictionary, and so is the value returned by @"key", inside that is the Array you seek.

نصائح أخرى

Forget the whole objectForKey thing, it's just

NSArray *values = json[@"parameters"][@"key"][@"value];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top