Xiija Posted August 9, 2017 Share Posted August 9, 2017 (edited) trying to do nested objects, tried arrays but failed there too... premise: 2 notecards, one named rock, site1 # url1 site2 # url2 one named jazz site1 # url1 site2 # url2 ------- possible pre definitions? ------- info = llList2Json (JSON_OBJECT, [ "TITLE", JSON_NULL, "URL", JSON_NULL ] ); notecards = llList2Json( JSON_OBJECT, [] ); --------------------------------------------------------------------------------- example: CurrNC = rock, string title = site1, string url = url1 in the data server event: if (llJsonGetValue (notecards, [CurrNC] ) == JSON_INVALID) { notecards = llJsonSetValue (notecards, [CurrNC] ,info) ; // trying to create a "ROCK" object in the notecards object } title = site1; url = url1; if (llJsonGetValue (CurrNC, [title] ) == JSON_INVALID) // if there is not a JSON key-value pair in the JSON object, add one { notecards = llJsonSetValue (notecards, [CurrNC, "URL"] ,url) ; notecards = llJsonSetValue (notecards, [CurrNC, "TITLE"] ,title) ; } and then trying to get the syntax to get these infos? getInfo(string card) { list details = llJson2List (llJsonGetValue ( notecards,[card] ) ); list fields = llList2ListStrided (details, 0, -1, 2); list send = []; integer len = llGetListLength(fields); integer x; for(;x < len;++x) { string tmp = llList2String(fields,x); send += tmp + " @ " + llJsonGetValue (notecards, [card, tmp]); } llSay(0,"\nInfo for " + card + "\n" + llDumpList2String(send,"\n")); } thanx for any help Edited August 9, 2017 by Xiija Link to comment Share on other sites More sharing options...
arton Rotaru Posted August 11, 2017 Share Posted August 11, 2017 I guess we are all a little bit confused about what it exactly is you are trying to do, and what is not working. Link to comment Share on other sites More sharing options...
Xiija Posted August 12, 2017 Author Share Posted August 12, 2017 erm ok, can anyone please give a demonstration of how to nest a JSON obect in another object or an array? i'm not talking about the visualization of it, I.E. { "alpha": 1, "beta": [ "x", "y", "z" ], "gamma": { "a": 3.2, "b": true } } i'm talking about, how to write it in LSL.. i need to nest either an obect in an object, or an object in an array. right now I can do an object ( called stations) which I can set the key value pairs of "name" and "url" for multple entries in a notecard, ... what i'm trying to do is read Multiple notecards, and so have a higher level object or array to hold those notecard names, which will then hold the stations for that notecard. ... and how to call the info with llJsonGetValue() ....hope that is clearer? thanx for any help, X. Link to comment Share on other sites More sharing options...
arton Rotaru Posted August 12, 2017 Share Posted August 12, 2017 (edited) Something like this? string notecards; list glRockNC = [ "Rock 1 # R_Url 1", "Rock 2 # R_Url 2", "Rock 3 # R_Url 3"]; list glJazzNC = [ "Jazz 1 # J_Url 1", "Jazz 2 # J_Url 2", "Jazz 3 # J_Url 3"]; BuildJson(string _nc, list _lnc) { list KeyVal = []; //notecards = llJsonSetValue(notecards, ["Root", _nc], JSON_NULL); integer len = llGetListLength(_lnc); integer i; for(; i < len; ++i) { string sT = llList2String(_lnc, i); string name = llStringTrim(llList2String(llParseString2List(sT, ["#"], []), 0), STRING_TRIM); string value = llStringTrim(llList2String(llParseString2List(sT, ["#"], []), 1), STRING_TRIM); KeyVal += [name, value]; } notecards = llJsonSetValue(notecards, ["Root", _nc], llList2Json(JSON_OBJECT, KeyVal)); } GetUrl(string card, string _titles) { llOwnerSay("Title " + _titles + " @ " + llJsonGetValue(notecards,["Root", card, _titles])); } default { state_entry() { notecards = llList2Json(JSON_OBJECT, ["Root"]); } touch_start(integer total_number) { BuildJson("Rock", glRockNC); BuildJson("Jazz", glJazzNC); GetUrl("Rock", "Rock 1"); GetUrl("Jazz", "Jazz 2"); } } Edited August 13, 2017 by arton Rotaru Link to comment Share on other sites More sharing options...
Xiija Posted August 12, 2017 Author Share Posted August 12, 2017 (edited) Thanks, i kept at it and finally think I got it was a combination of bad syntax, code errors, and ..."i've been staring at this too long" here is the multi NC reader I would post a link in the wiki, but don't know if I can? Edited August 12, 2017 by Xiija 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now