2
我想發在身體中含有JSON對象的數組,像這樣的PUT請求的主體:TRESTRequest:如何添加一個數組作爲PUT請求
PUT http://hostname/api/items
[{"ID":1},{"ID":2},...]
使用如下代碼,我可以在體內與單個TJSONObject容易發送POST請求:
req := TRESTRequest.Create(nil);
req.Client := FRESTClient;
req.Method := TRESTRequestMethod.rmPOST;
req.Resource := 'api/items';
req.AddBody(someJSONObject);
req.Execute;
的Fiddler示出了請求爲具有正確的內容:
{"ID",1}
不過,如果我使用一個PUT請求,並添加TJSONArray作爲身體,而不是...
ja := TJSONArray.Create;
for jo in someJSONObjects do
ja.Add(jo);
req.Method := TRESTRequestMethod.rmPUT;
req.AddBody(ja);
提琴手顯示要求爲具有奇異的JSON內容的一大堆:
{"elements":{"items":[{"members":{"items":[{"jsonString":{"strBuffer":{"data":["I","D","","","","","","","","","","","","","",""],"length":2,"maxCapacity":2147483647},"owned":true},"jsonValue":{"strBuffer":{"data":["1","","","","","","","","","","","","","","",""],"length":1,"maxCapacity":2147483647},"owned":true},"owned":true}],...
它看起來像原始內存中對象的某種低級別序列化,而不是預期的JSON數組內容。
任何想法我做錯了什麼? AddBody方法上的documentation不是很有幫助。
謝謝你SOOOOOOO張貼您的問題的答案。幫助我出去了很多! – Pascal 2016-08-31 00:14:24