How to extract a json object that's inside a json object

前端 未结 3 1241
暖寄归人
暖寄归人 2021-02-04 12:16

Convert this:

{\"items\":[{\"id\":\"BLE89-A0-123-384\",\"weight\":\"100\",\"quantity\":3},
          ...    
          {\"id\":\"BLE10-A0-123-321\",\"weight\":\"         


        
3条回答
  •  执笔经年
    2021-02-04 12:56

    You need to do the following:

    
    var newJSON = {};
    for (var i = 0; i < oldJSON.items.length; i++) {
      newJSON[oldJSON.items[i].id] = oldJSON.items[i].quantity;
    }
    

提交回复
热议问题