Dan*_*any 1 xcode json objective-c uilabel ios
我的json文件看起来像这样
[{"id":"1","category":"New Category1","title":"New Product2","description":"Please type a description1","imgurl":"http:\/\/s.wordpress.org\/about\/images\/wordpress-logo-notext-bg.png","spectitle":"Specification","specvalue":"Value"},{"id":"2","category":"Mobile","title":"Samsung","description":"Please type a description","imgurl":"http:\/\/s.wordpress.org\/about\/images\/wordpress-logo-notext-bg.png","spectitle":"Price","specvalue":"100$"}]
Run Code Online (Sandbox Code Playgroud)
我有4个标签,必须在单个标签中打印id,类别,标题,描述.我已成功解析整个json对象并打印在一个标签中.我需要显示所有json对象和相应的类别到相应的标签.
NSString *labelstring =[NSString stringWithFormat:@"%@",[json objectAtIndex:0]];
label1.text=[NSString stringwithformat: objectForKey:@"id"];
label2.text=[NSString stringwithformat:objectForKey:@"category"];
label3.text=[NSString stringwithformat:objectForKey:@"title"];
label4.text=[NSString stringwithformat:objectForKey:@"description"];
Run Code Online (Sandbox Code Playgroud)
这里json是NSArray的一个变量,有URL信息和那些东西......但如果我试图获得个人价值,我无法得到它..指导请...
(void)viewDidLoad
{
[super viewDidLoad];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://advantixcrm.com/prj/mitech/index.php/api/appconfig/Mg"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];
NSArray *array=[jsonArray objectForKey:@"info"];
for (int i=0; i<[array count]; i++) {
_label.text = [[array objectAtIndex:i]objectForKey:@"restaurant_location"]);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4665 次 |
| 最近记录: |