如何在objective-c中创建json [英] how to create json in objective-c
本文介绍了如何在objective-c中创建json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSData* jsonDataToSendTheServer;
NSDictionary *setUser = [NSDictionary
dictionaryWithObjectsAndKeys:[@"u" stringByAppendingString:my.id],@"id",
@"GET_USER_INFO",@"command",
@"",@"value",
nil];
NSDictionary *setUser = [NSDictionary
dictionaryWithObjectsAndKeys:[@"u" stringByAppendingString:my.id],@"id",
@"GET_USER_INFO",@"command",
@"",@"value",
nil];
NSLog(@"%@", jsonDataToSendTheServer);
这是我的代码。当我运行上面的代码时,我得到这个印刷品
Here is my code. When I run above code I get this print
<7b226964 223a2275 35383738 37373334 31222c22 636f6d6d 616e6422 3a224745 545f5553 45525f49 4e464f22 2c227661 6c756522 3a22227d>
我不知道我是否可以创建一个json。
I don't have any idea whether I can created a json or not.
我该如何解决这个问题?
How can I fix this?
推荐答案
你错过了这一行来转换它to json
You're missing this line to convert it to json
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:setUser
options:NSJSONWritingPrettyPrinted error:&error];
这是NSJSONSerialization的教程,它可以帮到你:
http://www.raywenderlich.com/5492/working-with-json-in-ios -5
Here's a tutorial on NSJSONSerialization that may help you: http://www.raywenderlich.com/5492/working-with-json-in-ios-5
之后,您可以将NSData转换为NSString进行打印:
After that, you can convert the NSData to an NSString to print:
这篇关于如何在objective-c中创建json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文