JSON对象转为数组对象函数json_decode()

1
2
3
4
{
"AR":{"ID":2850,"name":"Argentina","country_code":"AR","currency":"ARS"},
"AU":{"ID":2949,"name":"Australia","country_code":"AU","currency":"AUD"},
}
1
2
3
4
5
6
7
8
//从文件中读取数据到PHP变量
$json_string = file_get_contents("http://www.demo.com/json/xxx.json");
//把JSON字符串转成PHP数组
$data = json_decode($json_string,true);
//输出数组内容
$meta_value = $data[$meta_value]["name"];
//更新文章meta信息
update_post_meta($post_id, $meta_key, $meta_value);