0

Hi I am getting a weird issue in JSON decode, JSON is getting decoded correctly locally, but on my server the json_decode function returns NULL.

This is the JSON that I am posting from my test page:

[
 {
 "pictureTaken": 0,
 "unit_id": 20192,
 "id": 2,
 "deficiency_id": 155,
 "last_modifier_id": 4,
 "comments": "Living room",
 "level": 3,
 "location": "Living room",
 "property_id": 26,
 "inspectable_item_id": 44,
 "building_id": -769876698
 } 
]

now when I do var_dump(json_deocde($_POST['data'], true)); I get NULL response.

when I do echo $_POST['data']; I get:

[ { \"pictureTaken\": 0, \"unit_id\": 20192, \"id\": 2, \"deficiency_id\": 155, \"last_modifier_id\": 4, \"comments\": \"Living room\", \"level\": 3, \"location\": \"Living room\", \"property_id\": 26, \"inspectable_item_id\": 44, \"building_id\": -769876698 } ]

I think due to these \" json_decode is not working, kindly help me in fixing this issue,

Some Server Info:

PHP Version 5.2.17 json version 1.2.1

Sara
8,2521 gold badge40 silver badges52 bronze badges
asked Aug 30, 2013 at 16:54

2 Answers 2

3

You have magic quotes enabled on your server. Disable them.

answered Aug 30, 2013 at 16:56
Sign up to request clarification or add additional context in comments.

3 Comments

According to the PHP docs, magic quotes are deprecated. This guy is using an old version of PHP. Time to upgrade.
@Moshe, i am using BlueHost hosting, and they are using PHP Version 5.2.17, so i can not do anything on PHP version...
Ugh, I used to use BlueHost. I can't recommend them because of how they will shut down your site without warning at the first sign of even trying to use the "unlimited" stuff they offer you. If you're looking for a reliable, no-nonsense host, try TSOHost
0

you can always do this : var_dump(json_deocde(str_replace("\",$_POST['data']), true));

that would remove the slashes from your json string

answered Aug 30, 2013 at 17:55

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.