1

我有NSString回应

  {"id":"44","message":"1"} , 

我想获得的价值

"id" 

"message" 

分别地。NSString这是来自服务器的响应。

4

4 回答 4

3

试试这个。

NSData *data = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSDictionary dictionaryWithDictionary=:[NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableLeaves error:&error]];
NSLog(@"id:%@", [dict objectForKey:@"id"]);
NSLog(@"message:%@", [dict objectForKey:@"message"]);

它会解决的。

于 2013-08-27T07:42:54.727 回答
0

那么你可以得到这样的回应

NSData *data = [stringResponse dataUsingEncoding:NSUTF8StringEncoding];
id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@", [result objectForKey:@"id"]);

希望这可以帮助...

于 2013-08-27T07:35:30.263 回答
0
NSData *data = [stringResponse dataUsingEncoding:NSUTF8StringEncoding];
//instead of id use NSDictionary
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@", [result objectForKey:@"id"]);
于 2013-08-27T07:37:48.300 回答
0

你可以试试这个:

NSDictionary *dic=[response JSONValue];
NSDictionary *id=[dic objectForKey:@"id"];
NSString * message =[dic objectForKey:@"message"];
 NSLog(@"id :%@   Message:%@ ",id,message);

祝你好运!

于 2013-08-27T07:39:11.890 回答