<small id='3Ileb'></small><noframes id='3Ileb'>

<legend id='3Ileb'><style id='3Ileb'><dir id='3Ileb'><q id='3Ileb'></q></dir></style></legend>
    1. <tfoot id='3Ileb'></tfoot>
      1. <i id='3Ileb'><tr id='3Ileb'><dt id='3Ileb'><q id='3Ileb'><span id='3Ileb'><b id='3Ileb'><form id='3Ileb'><ins id='3Ileb'></ins><ul id='3Ileb'></ul><sub id='3Ileb'></sub></form><legend id='3Ileb'></legend><bdo id='3Ileb'><pre id='3Ileb'><center id='3Ileb'></center></pre></bdo></b><th id='3Ileb'></th></span></q></dt></tr></i><div id='3Ileb'><tfoot id='3Ileb'></tfoot><dl id='3Ileb'><fieldset id='3Ileb'></fieldset></dl></div>
          <bdo id='3Ileb'></bdo><ul id='3Ileb'></ul>
      2. 如何将 JSON 解析为 Objective C - SBJSON

        时间:2023-10-03

        <small id='DCfXm'></small><noframes id='DCfXm'>

        <legend id='DCfXm'><style id='DCfXm'><dir id='DCfXm'><q id='DCfXm'></q></dir></style></legend>
          <bdo id='DCfXm'></bdo><ul id='DCfXm'></ul>

            <tfoot id='DCfXm'></tfoot>

            • <i id='DCfXm'><tr id='DCfXm'><dt id='DCfXm'><q id='DCfXm'><span id='DCfXm'><b id='DCfXm'><form id='DCfXm'><ins id='DCfXm'></ins><ul id='DCfXm'></ul><sub id='DCfXm'></sub></form><legend id='DCfXm'></legend><bdo id='DCfXm'><pre id='DCfXm'><center id='DCfXm'></center></pre></bdo></b><th id='DCfXm'></th></span></q></dt></tr></i><div id='DCfXm'><tfoot id='DCfXm'></tfoot><dl id='DCfXm'><fieldset id='DCfXm'></fieldset></dl></div>

                    <tbody id='DCfXm'></tbody>
                  本文介绍了如何将 JSON 解析为 Objective C - SBJSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  能否请您告诉我如何传递如下所示的 JSON 字符串:

                  Could you please tell me how to pass a JSON String which looks like this:

                  {"lessons":[{"id":"38","fach":"D","stunde":"t1s1","user_id":"1965","timestamp":"0000-00-00 00:00:00"},{"id":"39","fach":"M","stunde":"t1s2","user_id":"1965","timestamp":"0000-00-00 00:00:00"}]}
                  

                  我试过这样:

                  SBJSON *parser =[[SBJSON alloc] init];
                      NSArray *list = [[parser objectWithString:JsonData error:nil] copy];
                      [parser release];
                      for (NSDictionary *stunden in list)
                      {
                          NSString *content = [[stunden objectForKey:@"lessons"] objectForKey:@"stunde"];
                  
                      }
                  

                  提前致谢

                  最好的问候

                  推荐答案

                  请注意,您的 JSON 数据具有以下结构:

                  Note that your JSON data has the following structure:

                  1. 顶级值是一个对象(字典),它有一个名为课程"的属性
                  2. 课程"属性是一个数组
                  3. lessons"数组中的每个元素都是一个对象(包含课程的字典),具有多个属性,包括stunde"

                  对应的代码是:

                  SBJSON *parser = [[[SBJSON alloc] init] autorelease];
                  // 1. get the top level value as a dictionary
                  NSDictionary *jsonObject = [parser objectWithString:JsonData error:NULL];
                  // 2. get the lessons object as an array
                  NSArray *list = [jsonObject objectForKey:@"lessons"];
                  // 3. iterate the array; each element is a dictionary...
                  for (NSDictionary *lesson in list)
                  {
                      // 3 ...that contains a string for the key "stunde"
                      NSString *content = [lesson objectForKey:@"stunde"];
                  
                  }
                  

                  几个观察:

                  • -objectWithString:error:中,error参数是一个指向指针的指针.在这种情况下,使用 NULL 而不是 nil 更为常见.not 传递 NULL 并使用 NSError 对象检查错误也是一个好主意,以防方法返回 nil

                  • In -objectWithString:error:, the error parameter is a pointer to a pointer. It’s more common to use NULL instead of nil in that case. It’s also a good idea not to pass NULL and use an NSError object to inspect the error in case the method returns nil

                  如果 jsonObject 仅用于该特定方法,您可能不需要复制它.上面的代码没有.

                  If jsonObject is used only in that particular method, you probably don’t need to copy it. The code above doesn’t.

                  这篇关于如何将 JSON 解析为 Objective C - SBJSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <legend id='xc7tV'><style id='xc7tV'><dir id='xc7tV'><q id='xc7tV'></q></dir></style></legend>

                    <small id='xc7tV'></small><noframes id='xc7tV'>

                      <bdo id='xc7tV'></bdo><ul id='xc7tV'></ul>

                            <tbody id='xc7tV'></tbody>
                          <i id='xc7tV'><tr id='xc7tV'><dt id='xc7tV'><q id='xc7tV'><span id='xc7tV'><b id='xc7tV'><form id='xc7tV'><ins id='xc7tV'></ins><ul id='xc7tV'></ul><sub id='xc7tV'></sub></form><legend id='xc7tV'></legend><bdo id='xc7tV'><pre id='xc7tV'><center id='xc7tV'></center></pre></bdo></b><th id='xc7tV'></th></span></q></dt></tr></i><div id='xc7tV'><tfoot id='xc7tV'></tfoot><dl id='xc7tV'><fieldset id='xc7tV'></fieldset></dl></div>
                        1. <tfoot id='xc7tV'></tfoot>