Difference between revisions of "JSON OBJECT"

From Second Life Wiki
Jump to navigation Jump to search
(Added examples and (hopefully!) clarified description.)
m (<lsl> tag to <source>)
 
(One intermediate revision by one other user not shown)
Line 9: Line 9:
|constants={{LSL Constants/JSON}}
|constants={{LSL Constants/JSON}}
|examples=Showing use to form a Json object:
|examples=Showing use to form a Json object:
<lsl>string jsonText;
<source lang="lsl2">string jsonText;


default
default
Line 24: Line 24:
llOwnerSay(jsonText); //  {"A":3,"B":"<1.000000, 1.000000, 1.000000>","C":"A phrase","D":3.141593}
llOwnerSay(jsonText); //  {"A":3,"B":"<1.000000, 1.000000, 1.000000>","C":"A phrase","D":3.141593}
}
}
}</lsl>
}</source>


Showing usage to determine if a Value within a Json text is an object:
Showing usage to determine if a Value within a Json text is an object:
<lsl>string jsonText;
<source lang="lsl2">string jsonText;


default
default
Line 57: Line 57:
}
}
}
}
}</lsl>
}</source>


|functions=
|functions=
Line 63: Line 63:
{{LSL DefineRow||[[llJsonValueType]]|}}
{{LSL DefineRow||[[llJsonValueType]]|}}
|events
|events
|cat1
|cat1=JSON
|cat2
|cat2
|cat3
|cat3

Latest revision as of 15:51, 23 January 2015

Description

Constant: string JSON_OBJECT = "﷑";

The string constant JSON_OBJECT has the value "﷑"

Used with the llList2Json function to indicate that the list provided is a strided list of "Key", Value pairs (which may be empty), and that a string representing a Json object will be returned.

Also a possible return value for the llJsonValueType function that indicates the Json data type of at the specifier location within a given Json text is, in fact, a JSON_OBJECT.

Related Articles

Constants

Type Flags Value Unicode Integer URL Encoded HTML Encoded Description
JSON_INVALID U+FDDO 64976 "%EF%B7%90" &#xFDD0; Value returned when inputs are not well formed.
JSON_OBJECT U+FDD1 64977 "%EF%B7%91" &#xFDD1;
JSON_ARRAY U+FDD2 64978 "%EF%B7%92" &#xFDD2;
JSON_NUMBER U+FDD3 64979 "%EF%B7%93" &#xFDD3;
JSON_STRING U+FDD4 64980 "%EF%B7%94" &#xFDD4;
JSON_NULL U+FDD5 64981 "%EF%B7%95" &#xFDD5;
JSON_TRUE U+FDD6 64982 "%EF%B7%96" &#xFDD6;
JSON_FALSE U+FDD7 64983 "%EF%B7%97" &#xFDD7;
JSON_DELETE U+FDD8 64984 "%EF%B7%98" &#xFDD8; Used with llJsonSetValue to remove a key-value pair.

Functions

•  llList2Json
•  llJsonValueType

Examples

Showing use to form a Json object:

string jsonText;

default
{
	state_entry()
	{
		// NOTE: All even numbered elements in the supplied list MUST be strings or JSON_INVALID will be returned!
		jsonText = llList2Json(JSON_OBJECT, ["A", 3, "B", <1.0,1.0,1.0>, "C", "A phrase", "D", PI]);
	}
	touch_start(integer total_number)
	{
		// In the resulting Json object, "Keys" are separarted from Values by a colon (:)
		// and "Key":Value pairs by a comma (,).
		llOwnerSay(jsonText); //  {"A":3,"B":"<1.000000, 1.000000, 1.000000>","C":"A phrase","D":3.141593}
	}
}

Showing usage to determine if a Value within a Json text is an object:

string jsonText;

default
{
	state_entry()
	{
		// Set jsonText to [3,{"A":77,"B":66},"A phrase"]
		// A Json array whose second element is a Json object
		jsonText = "[3,{\"A\":77,\"B\":66},\"A phrase\"]";
		llOwnerSay(jsonText);
	}
	touch_start(integer total_number)
	{
		// Test the entirety of the Json text to see if it's an object
		// Note use of the empty list for this
		if (llJsonValueType(jsonText, []) == JSON_OBJECT)
		{
			llOwnerSay("The supplied string is a Json object.");
		} else {
			llOwnerSay("The supplied string is not a Json object."); // TRUE
		}

		// Test second element of the array
		if (llJsonValueType(jsonText, [1]) == JSON_OBJECT)
		{
			llOwnerSay("The second element of the array is a Json object."); // TRUE
		} else {
			llOwnerSay("The second element of the array is not a Json object.");
		}
	}
}

Deep Notes

Search JIRA for related Issues

Signature

string JSON_OBJECT = "﷑";