简体   繁体   English

如何将json字符串解析为键值对?

[英]How to parse json string into key value pairs?

Unable to parse json string 无法解析json字符串

I have got the following hard coded json. 我有以下硬编码的json。 I tried converting it to dictionary and parse it but Im unable to do so. 我尝试将其转换为字典并解析,但是我无法这样做。

NSString *hcResponse  = @"{\"status\":1,\"value\":\"Successfully Login\"}";

How to parse such a json into key value pairs? 如何将这样的json解析为键值对?

Finally, I've figured it by myself 最后,我自己想通了

//convert the string to nsdata
NSData *jsonData = [hcResponse dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
//convert the data to json dictionary
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM