JSON and PHP, how to load a json file with php, turn it into an array and read the v |
JSON and PHP, how to load a json file with php, turn it into an array and read the v |
Luuk Lamers |
Nov 20 2008, 03:44 AM
Post
#1
|
Group: Members Posts: 1 Joined: 20-November 08 Member No.: 7,149 |
Hello,
I'm trying to read JSON data from a textfile 'sample.json' which is just a plain text file with the json extension I'm loading the file with $json1 = file_get_contents("sample.json"); Then I'm decoding it. I think it should be encoded for php to recognize it, but I'm not sure since I can't find any webpages that specify this. the decoding part: $json = json_decode($json1); then I do an echo to see if there's anything in the value, but I'm not sure if this is the way the decoder works. echo $json; I've tried multiple ways of putting the decoded/encoded JSON in an Array and accessing it but it keeps returning an empty string What is the best way to put a JSON file in a readable Array (or more) which I can then loop through and get values from? Thanks! |
Brian Chandler |
Nov 20 2008, 07:21 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Probably you want to check a value using print_r() not echo...
But basically this is stuff you have to ask where people know about JSON -- I had no idea what it was, 10 minutes ago. Have you looked here for example: http://gggeek.altervista.org/sw/article_20061113.html |
Lo-Fi Version | Time is now: 26th April 2024 - 06:29 PM |