LlJson2List: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Strife Onizuka (talk | contribs)
mNo edit summary
Wulfie Reanimator (talk | contribs)
m Removed the "barely useful example" by the author's own words.
 
(6 intermediate revisions by 5 users not shown)
Line 12: Line 12:
|constants
|constants
|examples=
|examples=
<source lang="lsl2">
default
{
    state_entry()
    {
        list items;
        string value = "89556747-24cb-43ed-920b-47caed15465f";
        items = llJson2List(value);
        // ["89556747-24cb-43ed-920b-47caed15465f"]
        string object = "{\"pi\": 3.14, \"set\": [1,2,3], \"status\": \"ok\"}";
        items = llJson2List(object);
        // ["pi", 3.140000, "set", "[1,2,3]", "status", "ok"]
        string array = "[0, 3.14, [1,2,3], {}]";
        items = llJson2List(array);
        // [0, 3.140000, "[1,2,3]", "{}"]
    }
}
</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llList2Json]]|}}
|also_functions={{LSL DefineRow||[[llList2Json]]|}}
Line 28: Line 49:
|cat3=Data Conversion
|cat3=Data Conversion
|cat4=JSON
|cat4=JSON
|history = Date of Release  [[ Release_Notes/Second_Life_Server/13#13.05.20.276191 | 20/05/2013 ]]
}}
}}

Latest revision as of 07:59, 15 December 2024

Summary

Function: list llJson2List( string src );
0.0 Forced Delay
10.0 Energy

This function takes a string representing JSON, and returns a list of the top level.
Returns a list made by parsing src, a string representing json.

• string src

To convert a list into a json formatted string use llList2Json.

Specification

See Json_usage_in_LSL

  • If the json represents a single item (number, string, true, false or null) then a list with 1 item will be returned.
  • If the json represents an object then a strided list of key, value pairs is returned. All values that are objects or arrays are returned as json strings.
  • If the json represents an array then a list of all items is returned. All values that are objects or arrays are returned as json strings.

Examples

default
{
    state_entry()
    {
        list items;

        string value = "89556747-24cb-43ed-920b-47caed15465f";
        items = llJson2List(value);
        // ["89556747-24cb-43ed-920b-47caed15465f"]

        string object = "{\"pi\": 3.14, \"set\": [1,2,3], \"status\": \"ok\"}";
        items = llJson2List(object);
        // ["pi", 3.140000, "set", "[1,2,3]", "status", "ok"]

        string array = "[0, 3.14, [1,2,3], {}]";
        items = llJson2List(array);
        // [0, 3.140000, "[1,2,3]", "{}"]
    }
}

See Also

Functions

•  llList2Json
•  llJsonGetValue
•  llJsonSetValue
•  llJsonValueType

Articles

•  Typecast

Deep Notes

History

Date of Release 20/05/2013

Signature

function list llJson2List( string src );