国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP-JSON-Konvertierung
代言
代言 2017-06-13 09:22:12
0
1
914
    {
        "a1": {
            "price": {
                "high": 4.68,
                "low": 3.75,
                "code": 1
            }
        },
        "a2": {
            "price": {
                "high": 2.77,
                "low": 2.29,
                "code": 1
            }
        }
    }

    現(xiàn)有上面的json,怎么把它轉(zhuǎn)換一下變成下面的格式:
{

    "china": {
        "cny": {
            "a1": {
                "high": 111,
                "low": 66
            },
            "a2": {
                "high": 44,
                "low": 22
            }
        }
    }

}


    

Meine Idee ist, zuerst den ursprünglichen JSON zu extrahieren, da der ursprüngliche JSON m?glicherweise ein anderes Format hat, und ihn dann einheitlich in das folgende Format zu konvertieren, was mit foreach nicht m?glich ist.

代言
代言

Antworte allen(1)
伊謝爾倫
$jsonStr = <<<CODE
    {
        "a1": {
            "price": {
                "high": 4.68,
                "low": 3.75,
                "code": 1
            }
        },
        "a2": {
            "price": {
                "high": 2.77,
                "low": 2.29,
                "code": 1
            }
        }
    }
CODE;

$nativeArray = json_decode($jsonStr, true);
$data = array();
foreach ($nativeArray as $key => $item) {
    unset($item['price']['code']);
    $data['china']['cny'][$key] = $item['price'];
}
echo json_encode($data);
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage