English 中文(简体)
如何得到分析值?
原标题:How to get the parse values?

我以以下方式写下代码。

NSDictionary* json = [NSJSONSerialization
    JSONObjectWithData:responseData 
 options:kNilOptions error:&error];

NSLog(@"%@",json);

印刷的字典是

(
        {
        Contents =         (
                        {
                Id = 2;
                LastUpdated = "/Date(1338048712847+0000)/";
                Title = "Webinar: HP & MS solutions for Mid-Market";
                Url = "http://infra2apps.blob.core.windows.net/content/VMMM019-HP-MS_MidMarket.wmv";
            },
                        {
                Id = 1;
                LastUpdated = "/Date(1338048712773+0000)/";
                Title = "Webinar: Private Cloud with HP & MS";
                Url = "http://infra2apps.blob.core.windows.net/content/VMPC012-HPMS_PrivateCloud.wmv";
            }
        );
        Id = 1;
        ImageUrl = "http://infra2apps.blob.core.windows.net/eventapp/black-microsoft-logo.jpg";
        Name = "Unified Communications & Collaborations";
        Sessions =         (
                        {
                Description = "Microsoft Lync delivers Unified Communication to help People connect in new ways, anytime, anywhere. Learn how HP and Microsoft are helping customers transform their business infrastrucutre and gain greater productivity by making every communication an interaction that is more collaborative and engaging.";
                EndDate = "/Date(1275822000000+0000)/";
                FriendlyName = TB3257;
                Id = 1;
                Location = "Building N-4105";
                Speakers =                 (
                                        {
                        Company = Microsoft;
                        Email = "[email protected]";
                        Name = "John Doe";
                        Title = "Group Manager";
                    }
                );
                StartDate = "/Date(1275818400000+0000)/";
                Title = "Connecting People in New Ways with Microsoft Lync";
            },
                        {
                Description = "Microsoft Lync delivers Unified Communication to help People connect in new ways, anytime, anywhere. Learn how HP and Microsoft are helping customers transform their business infrastrucutre and gain greater productivity by making every communication an interaction that is more collaborative and engaging.";
                EndDate = "/Date(1275825600000+0000)/";
                FriendlyName = TB3258;
                Id = 2;
                Location = "Building N-4105";
                Speakers =                 (
                                        {
                        Company = HP;
                        Email = "[email protected]";
                        Name = "Jane Doe";
                        Title = "Vice President";
                    },
                                        {
                        Company = Microsoft;
                        Email = "[email protected]";
                        Name = "John Doe";
                        Title = "Group Manager";
                    }
                );
                StartDate = "/Date(1275822000000+0000)/";
                Title = "Connecting People in New Ways with Microsoft Lync - Part 2";
            }
        );
    },

.............

And then store the content values into another dictionary after that i store into an array. the below code is to store the array id

   NSDictionary *boothmenucontents = [json valueForKey: @"Contents"]; 
  NSMutableArray *dictResponseboothmenucontentsArray = [[NSMutableArray alloc] initWithObjects: boothmenucontents,nil];
 for(int i = 0; i<[dictResponseboothmenucontentsArray count]; i++)

    {
        NSMutableArray *IdArrayboothmenucontentes=[[dictResponseboothmenucontentsArray objectAtIndex:i] valueForKey:@"Id"];

        NSLog(@"id array is %@",IdArrayboothmenucontentes);
        for(int k=0;k<[IdArrayboothmenucontentes count];k++)
        {
            NSString * strcontentId= [NSString stringWithFormat:@"%@",[IdArrayboothmenucontentes objectAtIndex:k]]; 

            NSLog(@"strcontentId%@",strcontentId);
            label.text=strcontentId;
            [boothmenuidarrayvalues addObject:strcontentId];


            NSLog(@"%@",boothmenuidarrayvalues);

        }


    }

最后我打印了彩虹彩虹价值

像这样打印

  "(
    2,
    1
)",
    "(
    4,
    3
)",
    "(
    6,
    5
)",
    "(
    8,
    7
)",
    "(
    10,
    9
)",
    "(
    12,
    11
)"

but i want to print content id only once but it print in a row in two times. May be i follow a wrong method please tell me how to give own root for that response.

求你帮帮我...

问题回答

也许它会帮助你。

NSMutableArray *contenstsArray = [contentsDictionary ValueForKey:@"Contents"]; //Suppose you already brought all the json data into contentsDictionary
NSMutableArray *idArray = [[NSMutableArray alloc] init];
for(NSMutableDictionary *idDic in contenstsArray) {
   NSString *idString = [idDic valueForKey:@"Id"];
   [idArray addObject:];
}

这条线看起来不对 :

NSMutableArray *IdArrayboothmenucontentes=[[dictResponseboothmenucontentsArray objectAtIndex:i] valueForKey:@"Id"];

我不确定你期待它做什么, 但是它看起来是抓取 dictResponsebouthmenucontents Array 中的 Ish 对象, 这是一种字典, 然后在字典中用密钥“ Id ” (是一个数字) 获得该对象, 所以IdArrayboutwenucontents 现在包含一个NSNO, 而不是一个数组 。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签