Combine 2 JSON objects in JQUERY

后端 未结 1 942
鱼传尺愫
鱼传尺愫 2021-01-29 01:42

Could you please help me on how to combine the below Result1 and Result2 JSON objects into single JSON such that i have Name,No,Avg,Subject1,Subject2 into single JSON object. I

相关标签:
1条回答
  • 2021-01-29 02:01

    See jQuery.extend()

    var x = {"Result1":"[{"NAME" : "Mark","No" : "23544","Avg" : "49"}]"}
    var y = {"Result2":"[{"Subject1" : "Maths","Subject2" : "Computers"}]"}
    
    var z = jQuery.extend({}, x.Result1[0], y.Result2[0]);
    // z.NAME, z.No, z.Avg, z.subject1...
    

    I'm not sure whether you've parsed the JSON string into a JavaScript object yet; but see jQuery.parseJSON() to see how you do this (be aware; parseJSON() will throw an error if you pass it invalid JSON).

    0 讨论(0)
提交回复
热议问题