我的回复json来自API如下:
{
"columnHeaders": [
{
"columnName": "id",
"columnType": "bigint",
"columnLength": 0,
"columnDisplayType": "INTEGER",
"isColumnNullable": false,
"isColumnPrimaryKey": true,
"columnValues": [],
"visibilityCriteria": []
},
{
"columnName": "client_id",
"columnType": "bigint",
"columnLength": 0,
"columnDisplayType": "INTEGER",
"isColumnNullable": false,
"isColumnPrimaryKey": false,
"columnValues": [],
"visibilityCriteria": []
},
{
"columnName": "countries",
"columnType": "int",
"columnLength": 0,
"columnDisplayType": "CODELOOKUP",
"isColumnNullable": false,
"isColumnPrimaryKey": false,
"displayName": "null",
"dependsOn": 0,
"orderPosition": 0,
"visible": false,
"mandatoryIfVisible": false,
"columnValues": [
{
"id": 19,
"value": "India",
"score": 0,
"parentId": 0
},
{
"id": 20,
"value": "USA",
"score": 0,
"parentId": 0
}
],
"columnCode": "countries",
"visibilityCriteria": []
}
}
]
现在我想将以下json添加到我现有的json数据中。
"columnValuesLookup": [
{
"id": 19,
"value": "English",
"score": 0,
"parentId": 0
},
{
"id": 20,
"value": "SA",
"score": 0,
"parentId": 0
}
],
如何将json数据添加到现有json对象中的特定索引,以便我的最终json看起来像
{
"columnHeaders": [
{
"columnName": "id",
"columnType": "bigint",
"columnLength": 0,
"columnDisplayType": "INTEGER",
"isColumnNullable": false,
"isColumnPrimaryKey": true,
"columnValues": [],
"visibilityCriteria": []
},
{
"columnName": "client_id",
"columnType": "bigint",
"columnLength": 0,
"columnDisplayType": "INTEGER",
"isColumnNullable": false,
"isColumnPrimaryKey": false,
"columnValues": [],
"visibilityCriteria": []
},
{
"columnName": "countries",
"columnType": "int",
"columnLength": 0,
"columnDisplayType": "CODELOOKUP",
"isColumnNullable": false,
"isColumnPrimaryKey": false,
"displayName": "null",
"dependsOn": 0,
"orderPosition": 0,
"visible": false,
"mandatoryIfVisible": false,
"columnValues": [
{
"id": 19,
"value": "India",
"score": 0,
"parentId": 0
},
{
"id": 20,
"value": "USA",
"score": 0,
"parentId": 0
}
],
"columnValuesLookup": [
{
"id": 19,
"value": "English",
"score": 0,
"parentId": 0
},
{
"id": 20,
"value": "SA",
"score": 0,
"parentId": 0
}
],
"columnCode": "countries",
"visibilityCriteria": []
}
}
]
答案 0 :(得分:0)
var o = JSON.parse(json1)
o.columnHeaders[2].columnValuesLookup = JSON.parse(json2).columnValuesLookup
JSON.stringify(o)