0

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

4

2 回答 2

3

我认为您误解了 JSON 的用途。您传递给的字符串-JSONValue不是有效的 JSON 字符串,因此它返回 nil。您不妨自己构建字典:

UIDevice *device = [UIDevice currentDevice];
NSDictionary *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:[device model], @"deviceModel", [device systemVersion], @"deviceSystemVersion", nil];

然后,如果您想要对象的 JSON 字符串表示形式(例如,用于发送到您的服务器):

NSString *jsonDeviceInfo = [deviceInfo JSONRepresentation];
于 2011-08-17T19:22:10.313 回答
1

你确定你的代码可以正常工作吗?您的 NSDictionary 似乎为零...

您能否发布 JSONValue 的实现?

如果对象未按预期打印,您始终可以-(NSString *) description通过扩展覆盖该方法,它将打印您指定的方式:)

于 2011-08-17T18:57:12.187 回答