Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取内部JSON对象delphi_Json_Delphi - Fatal编程技术网

读取内部JSON对象delphi

读取内部JSON对象delphi,json,delphi,Json,Delphi,我有这些JSON对象,我读得很好,但是当我读oauth值时,我得到了一个空结果 我怎么能读呢 { "status": true, "message": "Success", "items": { "id": 6, "name": "Tesst1", "email": "Test1@tesst.Test", "image": "https://www.we

我有这些JSON对象,我读得很好,但是当我读oauth值时,我得到了一个空结果

我怎么能读呢

{
        "status": true,
        "message": "Success",
        "items": {
            "id": 6,
            "name": "Tesst1",
            "email": "Test1@tesst.Test",
            "image": "https://www.website.com/images/man.png",
            "created_at": "2017-08-24 09:18:15",
            "updated_at": "2017-08-24 09:18:15",
            "oauth": {
                "token_type": "abc",
                "expires_in": 1296000,
                "access_token": "jI5NiwiZXhGVzIjpbXX0.RaC3ixxUeyYnCB6vNlwKsdjf09UeOwUJlcKmKErmE_LTAeQ-4fm8iBOKqUgpikTkyB3ztDGf4DAsaeEjUMqH76jZdbPHnX0vr676dCXkEunWoDEB8sYiHz7XRVgQ5W0O9yybA93mPO_XyrWPibkGW7GLQOApRD605N0e6vw0v9Kb_WQBim7zjTNqoLM1fSjgKJezFqf9_s3KIqBc4bjsayYLl7duzo2fzRmWtnGFfbsgO6YcaIz8ezNtWbtixLRMKnJEj1-MluqjWubsbq_gTI6yiyyac3_oY22Ge0QDdCtljadgO7wRz5VT5aJkxmJRB90u0ovm0tpGzYOO_4giY-J5egpOptjt2VZbPeM-vWPEo4-c6NYMZx6WqxBHjkZwiKUsM-tufzl5P5lFRJ9V_rBUBHEiSonTAk9FVDAwjqLc6N_IC1lsFDEC_3NBy4",
                "refresh_token": "def502003e7826477c1072497ad66d7f11ea29e81a0fafef6223a63b6a0a3d18de71165afb9a340d10facca3ac7ee955aac5786a5c66a39cdf77e3f6449458e07271cbcde699aabf4d7f72dad10d586c37497216552f88460e50e9ea4944214984d5b23bac04b5f8265d132"
            }
        }
    }
如果我将oauth作为JSON对象读取,我会得到一个关于不支持的转换的异常

不支持从TJSONObject到字符串的转换

我的代码有什么问题

if JsonRespnse <> '' then
    begin
      jsonObiekt := TJSONObject.ParseJSONValue
        (TEncoding.ASCII.GetBytes(JsonRespnse), 0) as TJSONObject;
      try
        try
          LoginValue := jsonObiekt.get('status').JsonValue;
          LoginValueIsTrue := StrToBool(LoginValue.value);

          if LoginValueIsTrue = True then
          begin
            ItemsValue := jsonObiekt.get('items').JsonValue;
            if ItemsValue is TJSONObject then
            begin
              strIdValue := ItemsValue.GetValue<string>('id');
              // strOuthValue := ItemsValue.GetValue<string>('oauth');
              OauthValue := TJSONObject(ItemsValue).get('oauth').JsonValue;
              if OauthValue is TJSONObject then
                Memo1.Lines.Add('oauth : ' + OauthValue.value);
            end;
          end;
        except
          on E: Exception do
            ShowMessage('Read JSON : ' + E.Message);
        end;
      finally
        jsonObiekt.Free;
      end;
    end;
如果JSONResponse为“”,则
开始
jsonObiekt:=TJSONObject.ParseJSONValue
(TEncoding.ASCII.GetBytes(jsonresponse),0)作为TJSONObject;
尝试
尝试
LoginValue:=jsonObiekt.get('status').JsonValue;
LoginValueIsTrue:=StrToBool(LoginValue.value);
如果LoginValueIsTrue=True,则
开始
ItemsValue:=jsonObiekt.get('items').JsonValue;
如果ItemsValue为TJSONObject,则
开始
strIdValue:=ItemsValue.GetValue('id');
//strOuthValue:=ItemsValue.GetValue('oauth');
OauthValue:=TJSONObject(ItemsValue).get('oauth').JsonValue;
如果OauthValue是TJSONObject,则
Memo1.Lines.Add('oauth:'+OauthValue.value);
结束;
结束;
除了
关于E:Exception-do
ShowMessage('Read JSON:'+E.Message);
结束;
最后
jsonObiekt.Free;
结束;
结束;
这包括你的问题吗


这包括您的问题吗?

谢谢您的回复,但问题是如何在
OauthValue
中获取oauth内容?@Phillipp H.oauth是item对象中的一个对象。在我的回答中,有一个示例演示了如何读取oauth对象的值。这是问题的答案:
OauthValue:=ItemsValue.GetValue('oauth')感谢您的回复,但问题是如何在
OauthValue
中获取oauth内容?@Phillipp H.oauth是item对象中的一个对象。在我的回答中,有一个示例显示了如何读取oauth对象的值。这是问题的答案:
OauthValue:=ItemsValue.GetValue('oauth')
strOuthValue := ItemsValue.GetValue<string>('oauth');
 if OauthValue is TJSONObject then
 begin
   Memo1.Lines.Add('oauth : ' + TJSONObject(OauthValue).ToString);
   Memo1.Lines.Add('oauth.token_type: ' + TJSONObject(OauthValue).Values['token_type'].ToString);
 end;