ios - 从服务获取数据 objective-c
<p><p>我对以下服务数据有一个小问题</p>
<pre><code>{
"DataTable": {
"DataList1": {
"StudentName": "Rakesh",
"StudentId": "13",
"StudentAge": "19",
"StudentAddress": "NewYork",
},
"DataList2": [{
"TeacherName": "Abhinav",
"TeacherId": "309",
"TeacherAge": "34",
"TeacherAddress": "NewYork",
}]
}
}
</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:@"DataTable"];
NSMutableArray * myArray = [ init];
if (([(NSString*)sdf isEqual: ])) {
UIAlertView *alert=[initWithTitle:@"Information" message:@"Currently there are no Data" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
;
;
}else {
];
jsonArray=;
refilldict=;
NSArray *keys = ;
for(int p=0 ; p<; 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<.count;i++){
NSString *keyName = [ objectAtIndex:i];
id objValue = ;
if(]){
NSArray *dataList2Array = (NSArray *)objValue;
NSLog(@"DataList2 Is :--%@",dataList2Array);
}
else {
NSDictionary *dataList1 = (NSDictionary *)objValue;
NSLog(@"DataList1 Is :--%@",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]