How to read key and value from a json string?

-1

I looked at some scripts and found nothing like that ...
Would I have been able to get just the part:

  
    

EAAAAAYsX7TsBAsdfosfbsJZBrbPOzrIXkkdoCgqg5oT15RC3ZC4QZCAVg8WLXugwhuYsuUi0E92XBEuTRge0HZC298cwYjNVPbnBZAIpOL9kshfisdisM3MuCg8kALZB0sKjunVWTSMmTYq1dUfK8eQ81i8aNcLmzsfhtdFON6XvmRA5oI8MCVZAOKPD3ROVQbwfwQZA54zGe6zrah6nw5Lz07VrAZD

  

With the command explode, or with another?

Below is the complete code of the way I'm generating:
I left bold for anyone to give me a little help, check it out more easily ...

{"session_key":"5.4Kt_bhcGLE530g.1500797842.40-122201203876562","uid":122201203876562,"secret":"a89s8we0e1f7767c747a0ca69084df","access_token":"**EAAAAAYsX7TsBAsdfosfbsJZBrbPOzrIXkkdoCgqg5oT15RC3ZC4QZCAVg8WLXugwhuYsuUi0E92XBEuTRge0HZC298cwYjNVPbnBZAIpOL9kshfisdisM3MuCg8kALZB0sKjunVWTSMmTYq1dUfK8eQ81i8aNcLmzsfhtdFON6XvmRA5oI8MCVZAOKPD3ROVQbwfwQZA54zGe6zrah6nw5Lz07VrAZD**","machine_id":"klt0WVBPc1BWzTSlzlsI0W8T","session_cookies":[{"name":"c_user","value":"122201203876562","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"\/","secure":true},{"name":"xs","value":"40:4Kt_bhcGLE530g:2:1500797842:10534:11960","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"\/","secure":true,"httponly":true},{"name":"fr","value":"8dsdsfsfUvar14Q.AWXQFSahahfsgsk88_-kEag.BWzwiw.0y.Flt.0.0.BZdFuS.AWV8aN6a","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"\/","secure":true,"httponly":true},{"name":"datr","value":"klt0WVBPc1BWzTSlzlsI0W8T","expires":"Tue, 23 Jul 2019 08:17:22 GMT","expires_timestamp":1563869842,"domain":".facebook.com","path":"\/","secure":true,"httponly":true}],"confirmed":true,"identifier":"email_sjn\u0040hotmail.com"}

Could someone tell me how I can achieve this?

Thank you.

    
asked by anonymous 23.07.2017 / 10:39

3 answers

1

It would not be best to use json_decode , since it is in json format.

Do so:

$json_string ='{"session_key":"5.4Kt_bhcGLE530g.1500797842.40-122201203876562","uid":122201203876562,"secret":"a89s8we0e1f7767c747a0ca69084df","access_token":"EAAAAAYsX7TsBAsdfosfbsJZBrbPOzrIXkkdoCgqg5oT15RC3ZC4QZCAVg8WLXugwhuYsuUi0E92XBEuTRge0HZC298cwYjNVPbnBZAIpOL9kshfisdisM3MuCg8kALZB0sKjunVWTSMmTYq1dUfK8eQ81i8aNcLmzsfhtdFON6XvmRA5oI8MCVZAOKPD3ROVQbwfwQZA54zGe6zrah6nw5Lz07VrAZD","machine_id":"klt0WVBPc1BWzTSlzlsI0W8T","session_cookies":[{"name":"c_user","value":"122201203876562","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"/","secure":true},{"name":"xs","value":"40:4Kt_bhcGLE530g:2:1500797842:10534:11960","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"/","secure":true,"httponly":true},{"name":"fr","value":"8dsdsfsfUvar14Q.AWXQFSahahfsgsk88_-kEag.BWzwiw.0y.Flt.0.0.BZdFuS.AWV8aN6a","expires":"Mon, 23 Jul 2018 08:17:22 GMT","expires_timestamp":1532333842,"domain":".facebook.com","path":"/","secure":true,"httponly":true},{"name":"datr","value":"klt0WVBPc1BWzTSlzlsI0W8T","expires":"Tue, 23 Jul 2019 08:17:22 GMT","expires_timestamp":1563869842,"domain":".facebook.com","path":"/","secure":true,"httponly":true}],"confirmed":true,"identifier":"email_sjn\u0040hotmail.com"}';

$value = json_decode($json_string);

var_dump($value->access_token);

The variable $value now contains the json values in object form.

Just do $value->chave to get the value. In your case, the value you want is access_token so replace chave with acess_token .

    
23.07.2017 / 11:14
0

@TaissonMartins, looking at the TAGs of your question I'm wondering that you can also use Javascript, so although you've already gotten the answer you needed, here's another option. I've separated your JSON just to make it easier to read ...

var myObj = {
    "session_key":"5.4Kt_bhcGLE530g.1500797842.40-122201203876562",
    "uid":122201203876562,
    "secret":"a89s8we0e1f7767c747a0ca69084df",
    "access_token":"**EAAAAAYsX7TsBAsdfosfbsJZBrbPOzrIXkkdoCgqg5oT15RC3ZC4QZCAVg8WLXugwhuYsuUi0E92XBEuTRge0HZC298cwYjNVPbnBZAIpOL9kshfisdisM3MuCg8kALZB0sKjunVWTSMmTYq1dUfK8eQ81i8aNcLmzsfhtdFON6XvmRA5oI8MCVZAOKPD3ROVQbwfwQZA54zGe6zrah6nw5Lz07VrAZD**",
    "machine_id":"klt0WVBPc1BWzTSlzlsI0W8T",
    "session_cookies":[
                                {
                                    "name":"c_user",
                                    "value":"122201203876562",
                                    "expires":"Mon, 23 Jul 2018 08:17:22 GMT",
                                    "expires_timestamp":1532333842,
                                    "domain":".facebook.com",
                                    "path":"\/",
                                    "secure":true
                                },
                                {
                                    "name":"xs",
                                    "value":"40:4Kt_bhcGLE530g:2:1500797842:10534:11960",
                                    "expires":"Mon, 23 Jul 2018 08:17:22 GMT",
                                    "expires_timestamp":1532333842,
                                    "domain":".facebook.com",
                                    "path":"\/",
                                    "secure":true,
                                    "httponly":true
                                },
                                {
                                    "name":"fr",
                                    "value":"8dsdsfsfUvar14Q.AWXQFSahahfsgsk88_-kEag.BWzwiw.0y.Flt.0.0.BZdFuS.AWV8aN6a",
                                    "expires":"Mon, 23 Jul 2018 08:17:22 GMT",
                                    "expires_timestamp":1532333842,
                                    "domain":".facebook.com",
                                    "path":"\/",
                                    "secure":true,
                                    "httponly":true
                                },
                                {
                                    "name":"datr",
                                    "value":"klt0WVBPc1BWzTSlzlsI0W8T",
                                    "expires":"Tue, 23 Jul 2019 08:17:22 GMT",
                                    "expires_timestamp":1563869842,
                                    "domain":".facebook.com",
                                    "path":"\/",
                                    "secure":true,
                                    "httponly":true
                                }
                            ],
    "confirmed":true,
    "identifier":"email_sjn\u0040hotmail.com"
}

console.log(myObj.access_token);

This will print:

**EAAAAAYsX7TsBAsdfosfbsJZBrbPOzrIXkkdoCgqg5oT15RC3ZC4QZCAVg8WLXugwhuYsuUi0E92XBEuTRge0HZC298cwYjNVPbnBZAIpOL9kshfisdisM3MuCg8kALZB0sKjunVWTSMmTYq1dUfK8eQ81i8aNcLmzsfhtdFON6XvmRA5oI8MCVZAOKPD3ROVQbwfwQZA54zGe6zrah6nw5Lz07VrAZD**
    
24.07.2017 / 04:22
0

Most would like to know if there is any way to do this through the explode command? For just the token part;

    
08.08.2017 / 04:59