【发布时间】:2016-01-09 05:46:00
【问题描述】:
使用 Delphi XE8 的 System.JSON,我无法解析 jsonarray
Json 示例:
{
"data":{
"current_condition":[
{
"cloudcover":"0",
"FeelsLikeC":"-9",
"FeelsLikeF":"15",
"humidity":"93",
"observation_time":"04:10 AM",
"precipMM":"0.0",
"pressure":"1007",
"temp_C":"-6",
"temp_F":"21",
"visibility":"10",
"weatherCode":"113",
"weatherDesc":[
],
"weatherIconUrl":[
],
"winddir16Point":"SE",
"winddirDegree":"130",
"windspeedKmph":"7",
"windspeedMiles":"4"
}
]
}
}
使用代码:
memores: TStringList;
currcond: TJSONObject;
memores2.Text := http.Get ('url');
JSONObject := TJSONObject.ParseJSONValue(memores2.Text) as TJSONObject;
Memores1.add('current_condition');
JSONObject2 := JSONObject.GetValue('data') as TJSONObject;
arrayjson := JSONObject2.ParseJSONValue('current_condition') as TJSONArray;
currcond := arrayjson.Items[0] as TJSONObject;
memores1.Add((currcond.GetValue('cloudcover').Value));
【问题讨论】:
-
函数 TJSONArray.GetCount 中的错误:整数;如果(FElements = nil)或(FElements.Count = 0)则开始,然后退出(0);结果:= FElements.Count;结尾; (FElements = nil)
-
完成 JSONObject2:=JSONObject.GetValue('data') as TJSONObject; arrayjson:=JSONObject2.GetValue('current_condition') as TJSONArray; currcond := arrayjson.Items[0] 作为 TJSONObject; // 解析 currcond/// memores1.Add((currcond.GetValue('cloudcover').Value));
标签: json delphi parsing system.json