Xcode 如何 NSLog 一个 JSON
有没有办法让 NSLog 打印出整个 JSON 文件。我目前说的
NSString *deviceInfo = [NSString stringWithFormat:@"%@ %@",
[[UIDevice currentDevice]model], [[UIDevice currentDevice]systemVersion]];
NSDictionary *json = [deviceInfo JSONValue];
NSLog(@"json file = %@", json);
是它正在打印“json file = (null)”
谢谢 克林顿
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);
And it is printing out "json file = (null)"
Thanks
Clinton
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您误解了 JSON 的用途。您传递给
-JSONValue
的字符串不是有效的 JSON 字符串,因此它返回 nil。您也可以自己构建字典:然后,如果您想要对象的 JSON 字符串表示形式(例如,用于发送到服务器):
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:Then if you want the JSON string representation of the object (for sending to your server, for instance):
你确定你的代码工作正常吗?你的 NSDictionary 似乎是 nil ...
你能发布 JSONValue 的实现吗?
如果对象未按预期打印,您始终可以通过扩展覆盖
-(NSString *) description
方法,它将打印您指定的方式:)Are you sure that your code works correctly? Your NSDictionary seems to be nil ...
Could you please post the implementation of JSONValue?
If an object doesn't print as expected you can always override the
-(NSString *) description
method through an extension and it will print how you've specified :)