Embarcadero RAD Studio XE

解析JSON字串

參考出處

uses ..., JSON, ...;

(省)


procedure TForm2.Button1Click(Sender: TObject);
var
  jso:TJSONObject;
  jv:TJSONValue;
  jstr:string;//要轉換的json字串
begin
  jso:=nil;
  jstr:='{"name":"陳富國","Interest":"閱讀"}';
   try
      jso:=TJSONObject.Create;
      jso:=TJSONObject.ParseJSONValue(tencoding.utf8.getbytes(jstr),0) as tjsonobject;
      jv:=jso.get('Interest').JsonValue;
      ShowMessage(jv.Value);
   finally
    jso.Free;
   end;
end;