json视图工具:http://www.bejson.com/jsonviewernew/
一、Json格式化,(看到数组里面又有数组一下子疑问不是合格json):尾门地址查询:
=>=>=>
{
"Addresses": [
"广东省 中山市 火炬开发区 在伟盛路附近 距离顷九327米",
"广东省 中山市 火炬开发区 在伟盛路附近 距离顷九327米"
],
"Points": [
{
"x": 113.456021761023,
"y": 22.5737174302826
},
{
"x": 113.456021761023,
"y": 22.5737174302826
}
],
"Places": [
[
"测试区域",
"su"
],
[
"测试区域",
"su"
]
]
}
procedure TForm10.btn1Click(Sender: TObject);
var
Jsonstr: string;
json: ISuperObject;
jsonAddress, jsonPlaceArray, jsonplace: TSuperArray;
i, j: Integer;
begin
Jsonstr := '{"Addresses":["广东省 中山市 火炬开发区 在伟盛路附近 距离顷九327米","广东省' +
'中山市 火炬开发区 在伟盛路附近 距离顷九327米"],"Points":[{"x":113.456021761023,"y":22.5737174302826},'
+ '{"x":113.456021761023,"y":22.5737174302826}],"Places":[["测试区域","su"],["测试区域","su"]]}'; json := SO(Jsonstr);
jsonAddress := json.A['Addresses']; // json.O['Addresses'].AsArray;
jsonPlaceArray := json.O['Places'].AsArray;
for i := to jsonPlaceArray.Length - do
begin
jsonplace := jsonPlaceArray.O[i].AsArray;
for j := to jsonplace.Length - do
begin
mmo1.Lines.Add(jsonplace.S[j]);
end;
end;
end;
处理代码
二、空调检测json结果:
=>=>=>
=>
{
"ACCResultList": [
{
"ACResultList": [
{
"ACOpenTime": "2015-12-22 10:15:16",
"ACCloseTime": "2015-12-22 11:16:16"
},
{
"ACOpenTime": "2015-12-22 13:15:16",
"ACCloseTime": "2015-12-22 13:16:16"
}
],
"AnalyzeAccOpenTime": "2015-12-22 9:00:00",
"AnalyzeAccCloseTime": "2015-12-22 14:00:00"
},
{
"ACResultList": [
{
"ACOpenTime": "2015-12-22 17:15:16",
"ACCloseTime": "2015-12-22 18:16:16"
},
{
"ACOpenTime": "2015-12-22 18:25:16",
"ACCloseTime": "2015-12-22 19:16:16"
}
],
"AnalyzeAccOpenTime": "2015-12-22 17:00:00",
"AnalyzeAccCloseTime": "2015-12-22 20:00:00"
}
],
"AnalyzeCarStopStatusStartTime": "2015-12-22 9:00:00",
"AnalyzeCarStopStatusEndTime": "2015-12-22 22:00:00",
"CommNo": "232321",
"AnalyzeCarSpeedLat": 2322112,
"AnalyzeCarSpeedLon": 0
}
procedure TForm10.btn2Click(Sender: TObject);
var
Jsonstr: String;
ACCResultArray: TSuperArray;
ACArray: TSuperArray;
i, j: Integer;
jsonNode:ISuperObject;
begin
// Jsonstr :=
// '{"ACCResultList":[{"ACResultList":[{"ACOpenTime":"2015-12-22 10:15:16","ACCloseTime":"2015-12-22 11:16:16"},'
// +'{"ACOpenTime":"2015-12-22 13:15:16","ACCloseTime":"2015-12-22 13:16:16"}]"AnalyzeAccOpenTime":"2015-12-22'+
// ' 9:00:00","AnalyzeAccCloseTime":"2015-12-22 14:00:00"},'
// +'{"ACResultList":[{"ACOpenTime":"2015-12-22 17:15:16","ACCloseTime":"2015-12-22 18:16:16"},'
// +'{"ACOpenTime":"2015-12-22 18:25:16","ACCloseTime":"2015-12-22 19:16:16"}],"AnalyzeAccOpenTime":"2015-12-22 '
// +'17:00:00","AnalyzeAccCloseTime":"2015-12-22 20:00:00"}],"AnalyzeCarStopStatusStartTime":"2015-12-22'
// +' 9:00:00","AnalyzeCarStopStatusEndTime":"2015-12-22 22:00:00","CommNo":"232321","AnalyzeCarSpeedLat":2322112,"AnalyzeCarSpeedLon":0}';
//此处发现两个情况,如果json数据放在 Memo中有空格回车键,转成string 转成不了 json对象;删除空格键可以
//2 string 拼接成一条也转成不了。如上屏蔽的拼接 不成功。
jsonNode := SO(mmo1.Lines.CommaText);
ACCResultArray := jsonNode.A['ACCResultList'];
// 或者类似这样 jsonNode.O['ACCResultList'].AsArray; for i := to ACCResultArray.Length - do
begin
ACArray := ACCResultArray.O[i].A['ACResultList']; //这样也可以ACCResultArray.O[i].O['ACResultList'].AsArray;
for j := to ACArray.Length - do
begin
mmo1.Lines.Add( ACArray.O[j].S['ACOpenTime']);
mmo1.Lines.Add(ACArray.O[j].S['ACCloseTime']);
end;
end;
end;
测试代码
个人总结:数组[] 里面的并列对象不可以有名字(因为是并列的,有不同名字就不是同样的了);Json 最外面的{} 前不可以有名字(如 "A":{}是不允许的);对象{}里面的对象前都必须要有名字; 不知道是否有问题。
例子1测试页:http://121.12.249.239:35080/arcgis/rest/services/PlaceService/MapServer/exts/PlaceServiceSOE/GetAddressAndPlace?groupid=156&points=%5B%7Bx%3A113.456021761023%2C+y%3A22.5737174302826%7D%5D&f=html