Quantcast
Channel: Help with consuming JSON feed with PHP & json_decode - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Help with consuming JSON feed with PHP & json_decode

$
0
0

I've having an issue with consuming a particular feed for a client. They have given me a remote URL and the response is a JSON string like so:

{"affiliate": [{"ID":"1", "COUNTRY":"EXAMPLE", "NETWORK":"EXAMPLE", "PRIMARY":"EXAMPLE"},{"ID":"2", "EXAMPLE":"EXAMPLE", "COUNTRY":"EXAMPLE", "NETWORK":"EXAMPLE", "PRIMARY":"EXAMPLE"},{"ID":"3", "TITLE":"EXAMPLE", "COUNTRY":"EXAMPLE", "NETWORK":"EXAMPLE", "PRIMARY":"EXAMPLE"}]}

For example purposes, I've shrank the feed to show the format, but in actuality there are hundreds of affiliates. Anyway, I want to use PHP json_decode because in the end, I need these affiliates in an associative array.

I've got something like this, but I just end up getting the raw string, and json_decode doesn't actually parse it into an associative array.

$request_url = "http://exampleurl.com/feed"; //returns feed like above$json = file_get_contents($request_url, true); //getting the file content$decode = json_decode($json, true);print_r($decode);

It seems like I need to maintain the "\n" characters in the feed itself, but these get stripped out when using:

file_get_contents

Anyway, I think you know what I'm after, I'm just not sure what I'm doing wrong. I appreciate the help in advance. I've tried using jquery with jsonp but it would be more ideal this way since I need to sort through the array afterward and it doesn't need to be asynchronous.

Acorn


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images