Ios IPhone解析JSON

Ios IPhone解析JSON,ios,json,Ios,Json,可能重复: 我有以下json: NSString *jsonResult = @"{\"code\":\"000\",\"message\":\"success\",\"datas\":[{\"datas\":[{\"service_name\":\"user_info\",\"name\":\"Account Test 32\",\"number\":123,\"company\":\"ABC\",\"currency\":\"USD\",\"balance\":\"1000\",\"pro

可能重复:

我有以下json:

NSString *jsonResult = @"{\"code\":\"000\",\"message\":\"success\",\"datas\":[{\"datas\":[{\"service_name\":\"user_info\",\"name\":\"Account Test 32\",\"number\":123,\"company\":\"ABC\",\"currency\":\"USD\",\"balance\":\"1000\",\"profit\":\"-80.00\",\"credit\":\"0.00\",\"equity\":\"1000.00\",\"leverage\":100,\"free_margin\":\"1000.00\",\"free_margin_mode\":1.0,\"server_name\":\"localhost\",\"stopout_level\":5,\"stopout_mode\":0}],\"service_name\":\"user_info\"}]}";

有人能举例说明如何解析吗?

您最好的选择是使用这样的JSON解析库。

您最好的选择是使用这样的JSON解析库。

试试这个。导入您也可以使用,但我更喜欢SBJson

#import "JSON.h"

// Create SBJSON object to parse JSON
SBJSON *parser = [[SBJSON alloc] init];

// parse the JSON string into an object - assuming json_string is a NSString of JSON data
NSDictionary *object = [parser objectWithString:jsonResult error:nil];
试试这个。导入您也可以使用,但我更喜欢SBJson

#import "JSON.h"

// Create SBJSON object to parse JSON
SBJSON *parser = [[SBJSON alloc] init];

// parse the JSON string into an object - assuming json_string is a NSString of JSON data
NSDictionary *object = [parser objectWithString:jsonResult error:nil];

为什么要解析JSON?这是您从web服务获得的负载吗?是的,它是来自web服务的负载。您为什么要解析JSON?这是您从web服务获得的有效负载吗?是的,它是来自web服务的有效负载。我如何获得数据数组中的值?您获得了
jsonResult
对吗?将其传递给JSON解析器。它将转换为Objective对象。。。这就是你需要的,对吗?所以我写的是解析器部分。在这里,您导入了json解析器并解析字符串……它仍然给我一个错误:SBJsonParser json=[[SBJsonParser alloc]init];n错误*jsonError;NSDictionary*parsedJSON=[json objectWithString:jsonResult错误:&jsonError];NSDictionary jsonValue=[parsedJSON objectForKey:@“代码”];NSLog(@“code:%@,[jsonValue objectForKey:@“code]”);那么它起作用了吗?为什么要发布代码?不起作用。很抱歉发布了代码。如何获取数据数组中的值?您的
jsonResult
正确吗?将其传递给JSON解析器。它将转换为Objective对象。。。这就是你需要的,对吗?所以我写的是解析器部分。在这里,您导入了json解析器并解析字符串……它仍然给我一个错误:SBJsonParser json=[[SBJsonParser alloc]init];n错误*jsonError;NSDictionary*parsedJSON=[json objectWithString:jsonResult错误:&jsonError];NSDictionary jsonValue=[parsedJSON objectForKey:@“代码”];NSLog(@“code:%@,[jsonValue objectForKey:@“code]”);那么它起作用了吗?为什么要发布代码?不起作用。很抱歉发布代码。