开发者

replace double quotes to parse JSON in PHP

i have following json format

{
    "status": "ACTIVE",
    "result": false,
    "isworking": false,
    "margin": 1,
    "employee": {
        "111": {
            "val1": 5.7000000000000002,
            "val2": "9/2",
            "val3": 5.7000000000000002 
        },
        "222": {
            "val1": 31.550000000000001,
            "val2": "29/1",
            "val3": 31.550000000000001 
        } 
    }
} 

how the problem is when i am trying to decode above json response in php using

json_decode($res,true) { true param for associative array } 

i am getting following result as few fields like "result":false is not "result":"false" i.e. at many of the places doubles quotes are missing in values of json. see in val1 and val3 fields

resultant data after decoding in php (associative array)

Array ( 
        [status] => > ACTIVE [result] => > [isworking] => > [margin] => >开发者_如何学Python 1 [employee] => > Array (
        [111] => > Array ( 
            [val1] => > 5.7 [val2] => > 9/2 [val3] => > 5.7 
        ) 
        [222] => > Array ( 
            [val1] => > 31.55 [val2] => > 29/1 [val3] => > 31.55 
        ) 
    ) 
) 

please help me on how would i insert double quotes in values ? Thanks


Actually, false is valid boolean value in json, and so json_decode it properly.

If you want "false" as string, your original json should be "false" too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜