我需要准备 JSON 并将其发送到网站。我正在使用TJSONObject. 我的代码很简单:
procedure TForm1.Button1Click(Sender: TObject);
var
JsonArray,JsonArray1:TJSONArray;
F,F1:TJSONObject;
begin
FJSONObject.AddPair('api_password','password');
FJSONObject.AddPair('method','POST');
F:=TJSONObject.Create;
F.AddPair('nest1','v1');
F.AddPair('nest2','v2');
JsonArray:=TJSONArray.Create;
JsonArray.AddElement(F);
FJSONObject.AddPair('Main array',JsonArray);
end;
结果,我得到了这个 JSON:
{
"api_password": "password",
"method": "POST",
"Main array": [
{
"nest1": "v1",
"nest2": "v2"
}
]
}
但是,根据网站的 API,我需要发送这个 JSON:
{
"api_password": "password",
"method": "POST",
"Main array": [
{
\"nest1\": \"v1\",
\"nest2\": \"v2\"
}
]
}
我怎样才能制作这个 JSON?