在我的iOS应用程序中,我成功收到了以下json(我认为是json):
{
data = {
"current_condition" = (
{
cloudcover = 16;
humidity = 59;
"observation_time" = "09:09 PM";
precipMM = "0.1";
pressure = 1010;
"temp_C" = 10;
"temp_F" = 49;
visibility = 10;
weatherCode = 113;
weatherDesc = (
{
value = Clear;
}
);
weatherIconUrl = (
{
value = "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0008_clear_sky_night.png";
}
);
winddir16Point = NW;
winddirDegree = 316;
windspeedKmph = 47;
windspeedMiles = 29;
}
);
request = (
{
query = "Lat 32.35 and Lon 141.43";
type = LatLon;
}
);
weather = (
{
date = "2013-01-15";
precipMM = "1.8";
tempMaxC = 12;
tempMaxF = 53;
tempMinC = 10;
tempMinF = 50;
weatherCode = 119;
weatherDesc = (
{
value = Cloudy;
}
);
weatherIconUrl = (
{
value = "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0003_white_cloud.png";
}
);
winddir16Point = NNW;
winddirDegree = 348;
winddirection = NNW;
windspeedKmph = 66;
windspeedMiles = 41;
},
{
date = "2013-01-16";
precipMM = "0.6";
tempMaxC = 13;
tempMaxF = 56;
tempMinC = 11;
tempMinF = 51;
weatherCode = 113;
weatherDesc = (
{
value = Sunny;
}
);
这里考虑的数据是什么?它是json对象的根?什么是现状?我想我需要解释如何解释这个json,所以我可以在tableview中显示它。我试图越过这个json tutorial,但那里的json完全不同!它使用":"分开键值,但这个json没有它。我完全糊涂了
答案 0 :(得分:0)
是的,看起来像JSON。看一下NSJSONSerialization
课程。它的污垢很简单易用。您将JSONObjectWithData:options:error:
方法传递给包含您要读取的JSON的NSData
对象,并返回表示JSON数据"对象图"的Foundation类对象。在你的情况下,它看起来像顶级对象是一个字典,所以你应该得到一个NSDictionary。
答案 1 :(得分:0)
看起来像是json。您可以通过这种方式操作数据。
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([greeting isKindOfClass:[NSDictionary class]]) {
//manipulate dictionary
}else if ([greeting isKindOfClass:[NSArray class]]) {
//manipulate array
}else{
//manipulate other
}