使用AJAX将JSON数据设置为PHP中的变量
问题描述:
使用twitter API twitteroauth,我检索了json格式的凭据,如下所示:
{oauth_token:XXXXXXXXXXXXXXXXXXXXXXX,oauth_token_secret:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,user_id:123456789,screen_name:myTwitterUsername}
我如何使用AJAX从上面的JSON结果中获取user_id和screen_name并将它们存储到PHP中的单独变量中,以便可以在UI上使用它们?
Hi,
Using the twitter API twitteroauth, I retrieved credentials in json format as shown below:
{"oauth_token":"XXXXXXXXXXXXXXXXXXXXXXX","oauth_token_secret":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","user_id":"123456789","screen_name":"myTwitterUsername"}
How would I use AJAX to get the user_id and screen_name from the JSON results above and store them into seperate variables in PHP so that they can be used on the UI?
答
问题不够明确,但你可能只需要PHPjson_decode
:
http://php.net/manual/en/function.json-decode.php [ ^ ]。-SA
The question is not clear enough, but it's possible that you just need PHPjson_decode
:
http://php.net/manual/en/function.json-decode.php[^].—SA