Keep order of objects inside a JSON String after they are parsed

后端 未结 6 1283
礼貌的吻别
礼貌的吻别 2021-01-18 09:42

I receive the following JSON string from an API function.

\"Inbound\": {
    \"callRelatedFields\": [\"ANI\",
    \"DNIS\"],
    \"objects\": {
        \"Con         


        
6条回答
  •  暖寄归人
    2021-01-18 09:47

    The parseJson returns data in object form and object doesn't has index. So we should define custom index of data array, if we want to keep the array index.

    Example:

    $arr[0] = array(
    'Contact'=>array(
    'key1'=>'val',
    )
    ); 
    $arr[1] = array(
    'Account'=>array(
    'key1'=>'val',
    )
    ); 
    

    It will produce the output as per the array index originally defined before parseJson function call.

提交回复
热议问题