views:

681

answers:

2

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;)

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 }]
+1  A: 

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'});
?>
Greg
A: 

You can use this syntax to access the node:

object['rssFeed.type']

.. Oh sorry I thought you were talking javascript..

eWolf
I wish PHP were more like JavaScript!
Skilldrick