php - json_decode returning an array of 1 -
I am trying to decode some JSON into a PHP array. Here's the code excerpt: The only thing that is back is '1'. I have checked JSONLint and it is a valid JSON, so I am thinking that json_decode is failing. I have also checked that what is the array before adding the day 3 key, and I still return '1', any help is appreciated! Actual code: These are the content of $ file (this is a text file) Then the outer external double quote will be JSON screw, and the tap will come back. Use it to detect it can also be a UTF-8 bomb or something else. . < However, the result of More specifically, you want < Code> print_r returned the output (instead of the Boolean breakthrough result then use: <
$ getfile = ""; $ Getfile = file_get_contents ($ file); If ($ getfile == "") {writeLog ("error reading file."); } Write ("getfile" is $ Getfile); WriteLog ("Dododing JSON Data"); $ Arr = json_decode ($ getfile, true); WriteLog ("decoded raw:". Print_r ($ arr)); WriteLog ("Editing Raw Data. Adding Data to the Day". $ Day); $ Arr ['day3'] = $ selector; WRITELOG (print_r ($ Arrival)); $ Newfile = json_enconde ($ arr); WRITELOG ($ newfile); If (file_put_contents ($ file, $ newfile)) {writeLog ("file" is written in. $ File); Echo $ newfile; } Else {writeLog ("file writting error"); }
{"fname": "bob", "lname": "Thomas "," Cascade ":" bustoma "," folk ":" race "," location ":" home 2 "}
We still do not know what is in your file "Thomas", "Cascade": "Bathoma", "People": "Race", "Location": "Home 2 "}" 1 is print_r directly output, you do not need echo instead for debugging
1 ) and then to log in.
TRUE Notice the parameters.
Comments
Post a Comment