php - json_decode returning an array of 1 -


I am trying to decode some JSON into a PHP array. Here's the code excerpt: $ getfile = "{" fname ":" Bob "," lname ":" Thomas "," Cascade ":" Bathoma "," Public ":" Reserves "," Location ":" home2 "}"; $ Arr = json_decode ($ getfile, true); $ Arr ['day3'] = $ selector; Echo (print_r ($ Arrival));

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:

  $ 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"); }   

These are the content of $ file (this is a text file)

  {"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 "}"

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 1 is print_r directly output, you do not need echo instead for debugging


More specifically, you want < Code> print_r returned the output (instead of the Boolean breakthrough result 1 ) and then to log in.

then use: <

TRUE Notice the parameters.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -