PHP json_decode表示法问题 [英] PHP json_decode notation issue

查看:58
本文介绍了PHP json_decode表示法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理我尝试解析的JSON文件中使用的表示法时遇到问题.一些节点具有. (句号)中的对象表示法转义 ($json = $article->rssFeed.url;)

I am having an issue dealing with the notation used in a JSON file I am trying parse. Some of the nodes have . (periods) in the names which escapes object-notation ($json = $article->rssFeed.url;)

我将如何选择节点.我是否需要str_replace.(句点),或者我可以使用其他符号吗?这是JSON的代码段:

How would I go about selecting the nodes. Do I need to str_replace the .(periods), or is there some other notation I can use? Here is a snippet of the JSON:

"docs": [{"rssFeed.type": "news", "rssFeed.url": "http://www.example.com/",  "score": 1.0 }]

推荐答案

您可以在名称周围使用花括号来访问属性:

You can use braces around the name to access the property:

<?php

$o = json_decode('{"docs": [{"rssFeed.type": "news", "rssFeed.url": "http://www.example.com/",  "score": 1.0 }]}');

var_dump($o->docs[0]->{'rssFeed.url'});
?>

这篇关于PHP json_decode表示法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆