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

后端 未结 6 1278
礼貌的吻别
礼貌的吻别 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:58

    @GregL is right the JSON parsed came in alphabetic or in case of a number in ascending order and to keep the order you'll need an incremented number logic like:

    var position_in_array = 0
    var name = 'screenPopSettings'
    
    object[`${position_in_array}${name}`] = value
    
    position_in_array += 1
    

提交回复
热议问题