简体   繁体   English

替换双引号以解析PHP中的JSON

[英]replace double quotes to parse JSON in PHP

i have following json format 我有以下json格式

{
    "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 问题是当我尝试使用php在json中解码以上响应时

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

i am getting following result as few fields like "result":false is not "result":"false" ie at many of the places doubles quotes are missing in values of json. 我得到以下结果,因为很少有像"result":false这样的字段不是"result":"false"即在json值中很多地方缺少双引号。 see in val1 and val3 fields 参见val1和val3字段

resultant data after decoding in php (associative array) 在php中解码后的结果数据(关联数组)

Array ( 
        [status] => > ACTIVE [result] => > [isworking] => > [margin] => > 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. 实际上, false是json中的有效布尔值,因此json_decode正确。

If you want "false" as string, your original json should be "false" too. 如果您想将“ false”作为字符串,则原始json也应为“ false”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM