数组到JSON在未预期的情况下失败" ="

时间:2015-10-06 13:17:06

标签: php arrays json

我试图让JSON将其发送到webservice。最终的json应该是这样的:

{
  "name": "Pravidlo",
  "partQualities": [
    "A",
    "O",
    "N"
  ],
  "residualValueMax": 100,
  "residualValueMin": 0,
  "selectionStrategy": "MIN_PRICE",
  "suppliers": [
    864,902,903,907,910,911,913,914,915,916,917,957
  ],
  "vehicleAgeMax": 100,
  "vehicleAgeMin": 0
}

我做了什么尝试:

    $data = array (
        "name" => "Pravidlo",           
        "partQualities" => array(
            'A', 'O', 'N'
        ),          
        "residualValueMax" = "100",
        "residualValueMin" = "0",
        "selectionStrategy" = "MIN_PRICE",
        "suppliers" = array(
            864,902,903,907,910,911,913,914,915,916,917,957
        ),   
        "vehicleAgeMax" = "100",
        "vehicleAgeMin" = "0"

    );                      
    // json encode data
    $data_string = json_encode($data);

我是如何在"意外"中得到错误的? residualValueMax和100之间的=。 有人可以告诉我如何创建这样的JSON? 感谢

2 个答案:

答案 0 :(得分:2)

您需要在数组声明中将=替换为=>

答案 1 :(得分:1)

对阵列使用 => 而非 =