菜鸟教程小白 发表于 2022-12-12 13:18:52

ios - 从服务获取数据 objective-c


                                            <p><p>我对以下服务数据有一个小问题</p>

<pre><code>{
    &#34;DataTable&#34;: {
      &#34;DataList1&#34;: {

            &#34;StudentName&#34;: &#34;Rakesh&#34;,
            &#34;StudentId&#34;: &#34;13&#34;,
            &#34;StudentAge&#34;: &#34;19&#34;,
            &#34;StudentAddress&#34;: &#34;NewYork&#34;,
      },
      &#34;DataList2&#34;: [{
            &#34;TeacherName&#34;: &#34;Abhinav&#34;,
            &#34;TeacherId&#34;: &#34;309&#34;,
            &#34;TeacherAge&#34;: &#34;34&#34;,
            &#34;TeacherAddress&#34;: &#34;NewYork&#34;,
      }]
    }
}
</code></pre>

<p>我可以从 DataList1 中获取数据,但不知道如何从 DataList2 中获取数据。下面是我尝试过的代码。请帮助找出解决方案。提前致谢</p>

<pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    ;
    NSString *responseString = [ initWithData:self.responseData encoding:NSUTF8StringEncoding];
    self.responseData = nil;

    NSMutableDictionary *sdf = [(NSDictionary*) objectForKey:@&#34;DataTable&#34;];
    NSMutableArray * myArray = [ init];

    if (([(NSString*)sdf isEqual: ])) {
      UIAlertView *alert=[initWithTitle:@&#34;Information&#34; message:@&#34;Currently there are no Data&#34; delegate:self cancelButtonTitle:@&#34;Ok&#34; otherButtonTitles:nil];
      ;
      ;
    }else {

      ];

      jsonArray=;
      refilldict=;
      NSArray *keys = ;
      for(int p=0 ; p&lt;; p++ )
      {
            NSString *value=];
            if (]||==0) {

                ];

            }

      }
lblStudentName.text = ;
      lblStudentId.text = ;
      lblStudentAge.text = ;

      lblStudentAddress.text = ;
}
self.navigationController.navigationBar.userInteractionEnabled = YES;
    ;
    ;
    HUD=nil;

}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>请使用下面的代码并在其中传递您的 Initial Json 字典。</p>

<pre><code>-(void)parseJsonData:(NSDictionary *)jsonDictionary{

    for(int i=0;i&lt;.count;i++){

      NSString *keyName = [ objectAtIndex:i];
      id objValue = ;

      if(]){

            NSArray *dataList2Array = (NSArray *)objValue;
            NSLog(@&#34;DataList2 Is :--%@&#34;,dataList2Array);
      }
      else {

            NSDictionary *dataList1 = (NSDictionary *)objValue;
            NSLog(@&#34;DataList1 Is :--%@&#34;,dataList1);
      }
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 从服务获取数据 objective-c ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43387685/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43387685/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 从服务获取数据 objective-c