Xcode如何NSLog JSON [英] Xcode how to NSLog a JSON
本文介绍了Xcode如何NSLog JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何方法可以使NSLog打印出整个JSON文件.我目前在说
Is there any way to get NSLog to print out an entire JSON file. I am currently saying
NSString *deviceInfo = [NSString stringWithFormat:@"%@ %@",
[[UIDevice currentDevice]model], [[UIDevice currentDevice]systemVersion]];
NSDictionary *json = [deviceInfo JSONValue];
NSLog(@"json file = %@", json);
它正在打印出"json文件=(空)"
And it is printing out "json file = (null)"
谢谢 克林顿
推荐答案
我认为您误解了JSON的用途.您传递给-JSONValue
的字符串不是有效的JSON字符串,因此返回nil.您也可以自己构建字典:
I think you’re misunderstanding what JSON is for. The string you’re passing to -JSONValue
isn’t a valid JSON string, so it’s returning nil. You might as well just construct the dictionary yourself:
UIDevice *device = [UIDevice currentDevice];
NSDictionary *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:[device model], @"deviceModel", [device systemVersion], @"deviceSystemVersion", nil];
然后,如果您想要对象的JSON字符串表示形式(例如,用于发送到服务器):
Then if you want the JSON string representation of the object (for sending to your server, for instance):
NSString *jsonDeviceInfo = [deviceInfo JSONRepresentation];
这篇关于Xcode如何NSLog JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文