PHP JSON对象解析

PHP JSON对象解析,php,json,Php,Json,我试图在PHP中解析一个JSON对象。我的努力最终导致了这个var_垃圾场: string(5) "Malta" string(2) "mt" string(11) "St Julian's" string(5) "Malta" string(2) "mt" string(11) "St Julian's" 现在我只想打印“马耳他”。所有的尝试都失败了,我需要一个提示,告诉我下一步该怎么做。你知道我该怎么做吗?谢谢 正在尝试分析此部分:“位置”: 我的代码片段: $jfo = json_dec

我试图在PHP中解析一个JSON对象。我的努力最终导致了这个var_垃圾场:

string(5) "Malta"
string(2) "mt"
string(11) "St Julian's"
string(5) "Malta"
string(2) "mt"
string(11) "St Julian's"
现在我只想打印“马耳他”。所有的尝试都失败了,我需要一个提示,告诉我下一步该怎么做。你知道我该怎么做吗?谢谢

正在尝试分析此部分:“位置”:

我的代码片段:

$jfo = json_decode($data, TRUE);

foreach ($jfo['content'] as $category) {
if (isset($category['title']) != null) {
}
if (isset($category['location']) != null) {



    foreach ($category['location'] as $location){
        var_dump($location);
        print_r($location);

尝试回显
$category['location']['country']
卸下此处的每个
它与循环您的位置数组有关

问题是您正在迭代
位置
中的每个元素,即
国家
国家代码
,以及
城市

这正是您所需要的:

$jfo = json_decode($data, TRUE);

foreach ($jfo['content'] as $content)
{
  echo $content['location']['country'];
}

我能得到那个对象的打印结果吗?看起来更像是一个循环而不是解码对象的
var\u dump
。@jon是的,我想是打印结果:string(5)“Malta”Maltastring(2)“mt”mtstring(11)“圣朱利安的”圣朱利安的string(5)“Malta”Maltastring(2)“mtstring”(11)“圣朱利安的”St Julian’根据JSONLINTTERED,您的json不正确,没有工作-它只打印第一个字符
$jfo = json_decode($data, TRUE);

foreach ($jfo['content'] as $content)
{
  echo $content['location']['country'];
}