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

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

+1 This will work, assuming the OP makes his code into valid JSON objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.