这里我使用了虚拟json数据并尝试在我的表视图中显示。但我过去常常检查控制台,但它无法正常工作。我错过了什么吗?
我应该像这样得到json:
[
{
"symbol": "ABC",
"price": 87.86,
"change": -0.41
},
{
"symbol": "GHI",
"price": 67.64,
"change": 0.05
}
]
我的代码:
NSDictionary *jsonObject = @[@{@"symbol":@"ABC",
@"price":@"87.86",@"change":@"-0.41"},
@{@"symbol":@"GHI",
@"price":@"67.64",@"change":@"0.05"}];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@" JSON DATA \n %@",[NSString stringWithCString:[jsonData bytes] encoding:NSUTF8StringEncoding]);
我收到警告:
Incompatible pointer types initializing 'NSDictionary *' with an expression of type 'NSArray *'
这是正确的格式还是我错过了什么?
当我尝试更改在控制台中获取null
的值时
为所有答案编辑:
NSArray *jsonObject;
jsonObject = @[@{@"Id1":@"mad",
@"people":@"12",@"total":@"20"},
@{@"Id2":@"normal",
@"people":@"13",@"total":@"20"}];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@" JSON DATA \n %@",[NSString stringWithCString:[jsonData bytes] encoding:NSUTF8StringEncoding]);
答案 0 :(得分:-1)
试试这个
NSArray *jsonObject;
jsonObject = @[@{@"symbol":@"ABC",
@"price":@"87.86",@"change":@"-0.41"},
@{@"symbol":@"GHI",
@"price":@"67.64",@"change":@"0.05"}];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@" JSON DATA \n %@",[NSString stringWithCString:[jsonData bytes] encoding:NSUTF8StringEncoding]);