标签:content new json格式 nbsp 数组 count option ctf tail
NSDictionary *result = value[@"data"];
if (![result isKindOfClass:[NSDictionary class]]) {
NSLog(@"data 不是字典");
if ([result isKindOfClass:[NSString class]]) {
NSData *data = [(NSString *)result dataUsingEncoding:NSUTF8StringEncoding];// 将数据格式转为UTF8
if (data) {
result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:NULL];
} else {
result = @{};
}
NSLog(@"解析data: %@", result);
} else {
result = @{};
}
}
// 数组里面 放了每个字典
commentlist = "[{\"user_id\":\"1\",
\"content\":\"[\\u998b\\u5634][\\u6293\\u72c2]\",
\"createtime\":\"1970-01-01 08:00:00\",
\"realname\":\"\\u90d1\\u98de\"},
{\"user_id\":\"1\",
\"content\":\"[\\u563b\\u563b][\\u563b\\u563b][\\u563b\\u563b]\\u641e\\u5b9a\",\"createtime\":\"1970-01-01 08:00:00\",\"realname\":\"\\u90d1\\u98de\"}, {\"user_id\":\"1\",\"content\":\"\\u641e\\u5b9a\",\"createtime\":\"1970-01-01 08:00:00\",\"realname\":\"\\u90d1\\u98de\"}]";
NSDictionary *result = value[@"data"];
if (![result isKindOfClass:[NSDictionary class]]) {
NSLog(@"data 不是字典");
if ([result isKindOfClass:[NSString class]]) {
NSData *data = [(NSString *)result dataUsingEncoding:NSUTF8StringEncoding];// 将数据格式转为UTF8
}}
NSData *resData = [[NSData alloc] initWithData:[@"[{\"user_id\":\"1\",\"content\":\"[\\u998b\\u5634][\\u6293\\u72c2]\",\"createtime\":\"1970-01-01 08:00:00\",\"realname\":\"\\u90d1\\u98de\"},{\"user_id\":\"1\",\"content\":\"[\\u563b\\u563b][\\u563b\\u563b][\\u563b\\u563b]\\u641e\\u5b9a\",\"createtime\":\"1970-01-01 08:00:00\",\"realname\":\"\\u90d1\\u98de\"},{\"user_id\":\"1\",\"content\":\"\\u641e\\u5b9a\",\"createtime\":\"1970-01-01 08:00:00\",\"realname\":\"\\u90d1\\u98de\"}]" dataUsingEncoding:NSUTF8StringEncoding]];
NSMutableDictionary *detailDic;
NSArray *arr = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
int count = arr.count;
NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:count];
for (int i = 0; i < count; i ++) {
detailDic = [arr objectAtIndex:i];
TestObject *testObject = [TestObject new];
testObject.user_id = [detailDic objectForKey:@"user_id"];
testObject.user_id = [detailDic objectForKey:@"content"];
testObject.user_id = [detailDic objectForKey:@"createtime"];
testObject.user_id = [detailDic objectForKey:@"realname"];
[tempArray addObject:testObject];
}
标签:content new json格式 nbsp 数组 count option ctf tail
原文地址:http://www.cnblogs.com/1018475062qq/p/7019259.html