本文介绍了如何在Objective-C iOS中解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用AFNetworking库在iOS的Objective-C中解析JSON
I want to parse JSON in Objective-C in iOS using AFNetworking library
{
"success": 1,
"row": [
{
"amount": 2800
}
]
}
代码-
arrAmount = [responseObject valueForKey:@"row"];
NSLog(@"%@",arrAmount);
NSString *strAmount =[NSString stringWithFormat:@"%@", [arrAmount valueForKey:@"amount"]];
self.lblAmount.text =[NSString stringWithFormat:@"%@",strAmount];
推荐答案
row
的响应包含数组而不是字典,因此从数组的第一个对象访问的数量.
Response of row
contain array not Dictionary, so access amount from first object of Array.
NSarray *arrAmount = [responseObject objectForKey:@"row"];
if arrAmount.count > 0 {
NSDictionary *dic = [arrAmount objectAtIndex:0];
NSString *strAmount = [NSString stringWithFormat:@"%d", [dic objectForKey:@"amount"]];
self.lblAmount.text = strAmount;
}
这篇关于如何在Objective-C iOS中解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!