I receive an array from a server which contains objects and association tables. So for example, I have this JSON result from the server:
var myEvent = {
"Event":{
"SessionTags":[
{
"SessionID":1,
"TagID":x
},
{
"SessionID":2,
"TagID":x
},
{
"SessionID":2,
"TagID":y
},
{
"SessionID":3,
"TagID":z
}
],
"Sessions":[
{
"ID":1,
"Name":"Advanced Tips",
},
{
"ID":2,
"Name":"Best Practices"
},
{
"ID":3,
"Name":"Code Fun"
},
"Tags":[
{
"ID":x,
"Name":"AJAX"
},
{
"ID":y,
"Name":"Android"
},
{
"ID":z,
"Name":"ASP.NET"
},
]
}
}
Notice the “SessionTags” object that is used as an association table. How do I add the right tag object in the session tag so I end up with this:
var myNewEvent = {
"Event":{
"Sessions":[
{
"ID":1,
"Name":"Advanced Tips",
"Tags":[
{
"ID":x,
"Name":"AJAX"
}
]
},
{
"ID":2,
"Name":"Best Practices",
"Tags":[
{
"ID":x,
"Name":"AJAX"
},
{
"ID":y,
"Name":"Android"
}
]
},
{
"ID":3,
"Name":"Code Fun",
"Tags":[
{
"ID":z,
"Name":"ASP.NET"
}
]
}
}
}
Try this:
I had to clean up your data slightly (IDs of x,y,z didn’t refer to any variables, and you also have some extra commas and a missing closing bracket) to get it to be workable for the example: