我将像这样的 stringify JSON 传递到我的 php 文件,
[{"Country Code":"bob","Country":"503","Description":"bobby","\"Minute Rate":"oregon","USD\"":"","\"$5 Talk Time":"\r"},{"Country Code":"steve","Country":"707","Description":"stevie","\"Minute Rate":"california","USD\"":"","\"$5 Talk Time":"\r"},{"Country Code":"dsfd","Country":"342","Description":"dfdfs","\"Minute Rate":"dfdsfs","USD\"":"","\"$5 Talk Time":"\r"},{"Country Code":"sada","Country":"342","Description":"sdsad","\"Minute Rate":"dfsffd","USD\"":"","\"$5 Talk Time":"\r"},{"Country Code":""}]
如何运行循环来在 php 中获取这些结果?
谢谢!
最佳答案
json_decode 函数采用 json 字符串作为其第一个参数,并采用可选的 bool 值 (true/false) 作为其第二个参数。第二个参数,如果设置为 true,则将 json 字符串作为关联数组返回,如果未设置,则返回一个对象。
json_array = json_decode($json, true); //Converts to array
foreach($json_array as $json){
echo $json['key']; //Key
echo $json->key; //Value of key
}
仅供引用
关于php - 使用ajax json和php中的短语发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28039545/