Functional requirements: Delphi use IdHTTP controls to a web server sends a request to receive the data returned, the server support for XML and JSON returns, notes mentioned need -- "the client specified ContentType=" application/JSON ", the server returns a JSON format "
Request statement: http://* * * *. * *. * *, * */* */API/getlastinfo? Tid=2123123 & amp; Key=1-2342-3546-2232-2342
I use the Edge directly input the above link in your browser, to return to normal:
{" dar ":" 2123123 ", "Time" : 0, "Dir" : 240, "Mileage" : 0 "Addr" : {" Province ", "shandong Province", "City" : "jinan"},}
I use the DELPHI writing, the code is as follows:
Url:='http://* * * *. * *. * *, * */API/* */getlastinfo? Tid=2123123 & amp; Key=1-2342-3546-2232-2342 ';
IdHTTP. Get (url, ts);//ts for TStringStream
Ts. Position:=0;
Ajson:=SuperObject. So (ts) DataString);//ajson ISuperObject
Dir:=ajson [' dir '] AsInteger;//this sentence error
I dropped my error statements comments, plus the Memo1. Lines. The Add (ajson. AsString) are identical; Want to see the return is correct, the result Memo1 display content is as follows:
Return should not JSON type, and still gibberish, clearly the browser test pass, why not, if use IdHTTP request error?
Online, etc., thank you!
CodePudding user response:
Great god, please feel free to commentCodePudding user response:
Not said the JSON format specified in the requirements? You add to go in and see the results,IdHTTP1. Request. ContentType:='application/json;//set the content type for json
CodePudding user response:
Results so try: (it's best to showmessage (ts) DataString)) to see if the results rightJo: SO=(UTF8Decode (HttpDecode (ts) DataString)));
Dir: Jo=[' dir '] Asinteger;
CodePudding user response: