0

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 am using it in JQUERY AJAX.

{"Result1":"[{"NAME" : "Mark","No" : "23544","Avg" : "49"}]"}

{"Result2":"[{"Subject1" : "Maths","Subject2" : "Computers"}]"}

Please help.

Thanks

pal
  • 1,202
  • 6
  • 17
  • 27

1 Answers1

5

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).

Matt
  • 74,352
  • 26
  • 153
  • 180