last day (14 days later) » 

5:36 PM
2
A: Resolve References in JSON : Javascript / JSON

Nina ScholzBasically a single loop proposal, which collects unresolved links and if found the it replaces the open parts with the object. var data = [{ "id": 1, "agent": { "id": 1, "firstName": "gghg", "lastName": "gh", "phone": "4543534", "admin": true }, "user": "agent@gmail.com" }, { "id": 2, "agent...

 
thank a lot... :) I get a random JSON object from the server and the JSON I get from server would have multiple objects referred just like the "agent" object.. I would also like to detect which properties need to be handled so that I don't have to care about the property names for each response from the server... How do I handle the general case?
 
you could use the key, which is to set, use as key for this object, like this[key][a[key]] =..., it depends on the specification, you have.
 
I am still a novice and bit confused how to do it as per your suggestion- could you please write it down for me? Note that some responses from the server will have multiple properties like "agent", "tenant", "provider", "admin" that will be internally referred and for any particular response I won't be knowing which properties are internally referred.
 
the list is known before?
 
nope, you won't know this list before- it changes on each response.
 
5:36 PM
how would you decide if the property is relevant or not?
 
if the property is an object, there is every possibility that there is an internal reference in the JSON
 
hi
 
nice :)
to the other properties: do the relay on the own id?
 
every property that is an object will have an id... seldom happens that they do not have an id... in the server side the internal reference is created to remove cyclic references I guess
 
5:41 PM
so in the example, { "id": 2, "agent": 1, --> "agent": { "id": 1, "firstName": "gghg"
agent id 1 maps to 1
 
exactly
 
and if some property, like abc: 5, then the property abc: { id: 5.. is taken.
 
yes
 
ok, i get it.
i can write that, but not now, more tomorrow morning.
 
sure, please add it to the answer at your convenience... thanks a lot for your time :)
 
5:47 PM
ok.
bye for now
 
bye :)
 

last day (14 days later) »