1,594
社区成员




procedure TForm2.Button1Click(Sender: TObject);
var
JSONObject: TJSONObject;
LItem: TJSONValue;
LJPair: TJSONPair;
weather: TJSONArray;
StrJson: String;
result: String;
i: Integer;
begin
JSONObject := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(StrJson), 0) as TJSONObject; // 创建JSONObject
JSONObject := (JSONObject.GetValue('results') as TJSONArray).Get(0) as TJSONObject; // 指向JSONObject
weather := JSONObject.GetValue('weather_data') as TJSONArray; // 指向JSONObject
......
weather.Free; // weather 指向JSONObject 释放了JSONObject
JSONObject.Free; // 前一句已释放,再次释放出现内存错误
// 前二句只能用一个,建议删除weather.Free;
end;