Quistess Alpha Posted January 13, 2023 Share Posted January 13, 2023 (edited) 30 minutes ago, Innula Zenovka said: I think it ought to be llJsonGetValue("test",["id",0]); but that doesn't work, and neither does anything else I try. "test" is a string which contains no JSON data. instead try llJsonGetValue(test,["playlists",0,"id"]); Maybe try looking at it one level at a time (the indentation on all these examples is horrible) test is a JSON object containing one key value pair Quote { "playlists": ... } to fetch the "..." you descend one level and ask for the "playlists", the value of which is Quote [ ... , ... ] a JSON array, to descend one more level, you ask for an index. at index 0, the ... is Quote { "id": ... "title": ... "description": ... "trackCount": ... } a JSON object, and to get one of the ...'s you ask for the key, for example "id". Edited January 13, 2023 by Quistess Alpha 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted January 13, 2023 Share Posted January 13, 2023 Just as an example, you can also use LSL to construct JSON strings: string JSON; JSON = llJsonSetValue(JSON,["playlists",0,"id"],"ID_1"); JSON = llJsonSetValue(JSON,["playlists",0,"title"],"TITLE_1"); JSON = llJsonSetValue(JSON,["playlists",0,"description"],"DESC_1"); JSON = llJsonSetValue(JSON,["playlists",0,"playcount"],"6"); JSON = llJsonSetValue(JSON,["playlists",1,"id"],"ID_2"); JSON = llJsonSetValue(JSON,["playlists",1,"title"],"TITLE_2"); JSON = llJsonSetValue(JSON,["playlists",1,"description"],"DESC_2"); JSON = llJsonSetValue(JSON,["playlists",1,"playcount"],"8"); llOwnerSay(JSON); Link to comment Share on other sites More sharing options...
Love Zhaoying Posted January 13, 2023 Share Posted January 13, 2023 19 minutes ago, Frionil Fang said: It's an array called playlists I like the way you explained that! Link to comment Share on other sites More sharing options...
Innula Zenovka Posted January 13, 2023 Author Share Posted January 13, 2023 58 minutes ago, Love Zhaoying said: "test" is the name of your variable. Try: llJsonGetValue(test, [..what to search for..]); "id" is not an array, so "0" won't find anything. What do you want to find? "Playlists" is an array, so llJsonGetValue(test, [playlists, 0, id]) would get the first playlist, and the value of "id". No matter what you are looking for, it appears "playlists" is your only top-level entry. So, no matter what you are looking for, it would have to be ["playlists",..]. Since you only have 2 "playlists" array entries, your choices are ["playlists",0..] and ["playlists",1..]. First level: "playlists": Key for KVP, of which the "value" is JSON_ARRAY. Next level: JSON_ARRAY, so you must provide an "index" to select an entry in the JSON_ARRAY Next level: JSON_OBJECT. so provide a "key".. Sorry, but I'm still not getting it. I think you're telling me to use string test = "{ \"playlists\": [{ \"id\": \"some key\", \"title\": \"Playlist 1\", \"description\": null, \"trackCount\": 20 }, { \"id\": \"another key\", \"title\": \"Playlist 2\", \"description\": null, \"trackCount\": 30 } ] }"; default { state_entry() { llOwnerSay(llJsonGetValue("test",["playlists",0,"id"])); } } but that can't be it, because it returns "[]". Clearly I'm misunderstanding something somewhere. 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted January 13, 2023 Share Posted January 13, 2023 (edited) 4 minutes ago, Innula Zenovka said: Clearly I'm misunderstanding something somewhere. you're not putting the variable into the function, you're putting in the string "test" which is not valid JSON. llOwnerSay(llJsonGetValue(test,["playlists",0,"id"])); // no quotes. Edited January 13, 2023 by Quistess Alpha 2 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted January 13, 2023 Share Posted January 13, 2023 7 minutes ago, Quistess Alpha said: you're not putting the variable into the function, you're putting in the string "test" which is not valid JSON. llOwnerSay(llJsonGetValue(test,["playlists",0,"id"])); // no quotes. ^^ yes, what I said in my first answer earlier! 🙂 @Innula ZenovkaYou can pass "any string" to llJsonGetValue(), and it won't give you a run-time error. So, perhaps you "meant" to pass the variable test but are passing "test" instead? 1 1 Link to comment Share on other sites More sharing options...
Innula Zenovka Posted January 13, 2023 Author Share Posted January 13, 2023 Thanks, both. Sorry. I have staring at this too long! 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