<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
	<id>http://i.bnu.edu.cn/wiki/index.php?action=history&amp;feed=atom&amp;title=LlJsonValueType</id>
	<title>LlJsonValueType - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="http://i.bnu.edu.cn/wiki/index.php?action=history&amp;feed=atom&amp;title=LlJsonValueType"/>
	<link rel="alternate" type="text/html" href="http://i.bnu.edu.cn/wiki/index.php?title=LlJsonValueType&amp;action=history"/>
	<updated>2026-06-01T03:38:06Z</updated>
	<subtitle>本wiki的该页面的版本历史</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>http://i.bnu.edu.cn/wiki/index.php?title=LlJsonValueType&amp;diff=722&amp;oldid=prev</id>
		<title>Ty：创建页面，内容为“{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}   {{函数详情 |函数名 = Function: string llJsonValueType( string json, list specifiers ); |…”</title>
		<link rel="alternate" type="text/html" href="http://i.bnu.edu.cn/wiki/index.php?title=LlJsonValueType&amp;diff=722&amp;oldid=prev"/>
		<updated>2020-08-20T13:44:17Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}   {{函数详情 |函数名 = Function: string llJsonValueType( string json, list specifiers ); |…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{函数详情&lt;br /&gt;
|函数名 = Function: string llJsonValueType( string json, list specifiers );&lt;br /&gt;
|参数= 参数：&lt;br /&gt;
string	json	–	A string serialization of a json object.&lt;br /&gt;
list	specifiers	–	A path to a value in the json parameter.&lt;br /&gt;
|返回值= 返回值：在 json 中返回指定值的类型的字符串。&lt;br /&gt;
&lt;br /&gt;
|注意事项=无&lt;br /&gt;
&lt;br /&gt;
|示例=&lt;br /&gt;
示例一&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//all these functions are untested functions that may have some very strange cases were they acd badly or where the comments are wrong&lt;br /&gt;
//see them as buggy PSEUDO-code and consider yourself lucky if there are less than 2 wrong counters and 4 bad pointers/names.&lt;br /&gt;
//they are more an example and a concept and unlikely fully functional AS IS.&lt;br /&gt;
 &lt;br /&gt;
string JisN(string j){if(llJsonValueType(j,[])==JSON_NUMBER  )return llJsonGetValue(j,[]);return &amp;quot;&amp;quot;;}&lt;br /&gt;
//return the JSON if &amp;quot;j&amp;quot; is a JSON_NUMBER, like j=&amp;quot;10.1234&amp;quot;  j=&amp;quot;-0.1234&amp;quot;  j=&amp;quot;3.14159&amp;quot;  j=&amp;quot;-1&amp;quot; j=&amp;quot;123456&amp;quot;   otherwise return &amp;quot;&amp;quot;;&lt;br /&gt;
//these would be sting representations of a float because j is a string.&lt;br /&gt;
//storing floats in a JSON will easily lose you a lot of accuracy. Integers stored in JSON may have a smaller range than 32-bit signed integers.&lt;br /&gt;
 &lt;br /&gt;
string JisA(string j){if(llJsonValueType(j,[])==JSON_ARRAY  )return llJsonGetValue(j,[]);return &amp;quot;&amp;quot;;}&lt;br /&gt;
//return the JSON if &amp;quot;j&amp;quot; is a JSON_ARRAY, like j=&amp;quot;[]&amp;quot;   j=&amp;quot;[1,2]&amp;quot;  j=&amp;quot;[[1],[3,4]]&amp;quot;                        otherwise return &amp;quot;&amp;quot;;&lt;br /&gt;
//these would be string representations of a (nested) list because j is a string.&lt;br /&gt;
 &lt;br /&gt;
string JisS(string j){if(llJsonValueType(j,[])==JSON_STRING )return llJsonGetValue(j,[]);return &amp;quot;&amp;quot;;}&lt;br /&gt;
//return the string that is stored in &amp;quot;j&amp;quot; if &amp;quot;j&amp;quot; is a JSON_STRING, like j=&amp;quot;\&amp;quot;PI\&amp;quot;&amp;quot;   j=&amp;quot;\&amp;quot;3.14\&amp;quot;&amp;quot;   j=&amp;quot;\&amp;quot;-1\&amp;quot;&amp;quot; otherwise return &amp;quot;&amp;quot;;&lt;br /&gt;
//these would be string representations of a string, typecast with \&amp;quot; as that within itself,&lt;br /&gt;
//because j is a string that is also able to store numbers and floats and (nested) lists ... as strings. &lt;br /&gt;
//this returns the string within &amp;quot;j&amp;quot; if &amp;quot;j&amp;quot; is &amp;quot;A string within a string&amp;quot;. &lt;br /&gt;
 &lt;br /&gt;
/*the above functions return strings to be used in simple &lt;br /&gt;
if(JisN(j)){} &lt;br /&gt;
if(JisA(j)){} &lt;br /&gt;
if(JisS(j)){} &lt;br /&gt;
//conditions as if they are booleans. //the boolean-ish condition works because &amp;quot;&amp;quot; equals FALSE within LSL.&lt;br /&gt;
The functions MAY return a JSON_STRING or JSON_ARRAY can be useful recursively as shown below:&lt;br /&gt;
*/&lt;br /&gt;
 &lt;br /&gt;
JstringPARSED(string j){&lt;br /&gt;
    //j=&amp;quot;\&amp;quot;PI\&amp;quot;&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;\&amp;quot;3.14\&amp;quot;&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;\&amp;quot;-1\&amp;quot;&amp;quot;;&lt;br /&gt;
    string JayWeHaveToGoDeeperS = JisS(JisS(j));&lt;br /&gt;
    llOwnerSay( JayWeHaveToGoDeeperS ); // says &amp;quot;PI&amp;quot;, or &amp;quot;&amp;quot;        , or &amp;quot;&amp;quot;         , because &amp;quot;3.14&amp;quot; is a JSON_NUMBER and &amp;quot;-1&amp;quot; is a JSON_NUMBER but not a JSON_STRING&lt;br /&gt;
    string JayWeHaveToGoDeeperN = JisN(JisS(j));&lt;br /&gt;
    llOwnerSay( JayWeHaveToGoDeeperN ); // says &amp;quot;&amp;quot;  , or &amp;quot;3.14000&amp;quot; , or &amp;quot;-1.0000&amp;quot;,   because &amp;quot;PI&amp;quot; is a JSON_STRING but &amp;quot;PI&amp;quot; is not a JSON_NUMBER &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
    if (llJsonValueType(j,[])==JSON_INVALID){}//would be TRUE for j=&amp;quot;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
//==== End of JstringPARSED(j) ===== start of Jnested(j) for  nested/recursive lists =====&lt;br /&gt;
 &lt;br /&gt;
Jnested(string j,list rope){//goes trough each value of a nested JSON_ARRAY and says its value and its &amp;quot;position-list&amp;quot;&lt;br /&gt;
    //j=&amp;quot;[]&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;[[1],[2]]&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;[-1,[2]]&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;[[1],-2]&amp;quot;;&lt;br /&gt;
    //j=&amp;quot;[[-3,-4]]&amp;quot;;  //the only true case HERE for = JisA(JisA(j)); below&lt;br /&gt;
    string JayWeHaveToGoDeeperA = JisA(JisA(j));&lt;br /&gt;
 &lt;br /&gt;
    string subJ=JisA(j);&lt;br /&gt;
    if (subJ){&lt;br /&gt;
        //here you actually have to loop trough each entry of the subJ JSON_LIST to test its TYPE for each entry (if we want to go deeper recursively)&lt;br /&gt;
        //You can go deeper once you know if entry number x is a JSON_LIST (NESTED!!!) or JSON_STRING (for some reason)&lt;br /&gt;
        //first see how many list entries there are; we go trough entries of subJ starting on the left until its a JSON_INVALID&lt;br /&gt;
        list types; &lt;br /&gt;
        integer i = -1;&lt;br /&gt;
        while (++i != -1){&lt;br /&gt;
             string type=llJsonValueType(j,[i]);//stores the TYPE of &amp;quot;j&amp;quot;'s entry at position i as &amp;quot;type&amp;quot;&lt;br /&gt;
             if (type==JSON_INVALID) i=-2; //this exits this the while-loop&lt;br /&gt;
             else types += [type];  // the list &amp;quot;types&amp;quot; will store all the JSON types, until the first invalid one is reached. (which which should also be for &amp;quot;out of bounds&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        //this is split in 2 loops to explain 1 task by splitting it in 2 smaller tasks. Actually the loops above and below could be merged easily. &lt;br /&gt;
 &lt;br /&gt;
        i=llGetListLength(types);//we now have a list that lists all JSON types of j; lets see how long it is; &lt;br /&gt;
        //and we loop trough all types, calling THIS function recursively if the list contains another nested list in it at position i&lt;br /&gt;
        while (i--){//I like to go reverse from right to left when ever possible, its faster (??) and costs less memory in LSL (??)&lt;br /&gt;
             if (llList2String(types,i)==JSON_ARRAY || llList2String(types,i)==JSON_OBJECT){&lt;br /&gt;
                  Jnested(llJsonGetValue(j,[i]));//the function calls itself here, recursively to go trough the nested JSON_ARRAY or JSON_OBJECT&lt;br /&gt;
            }&lt;br /&gt;
            else{&lt;br /&gt;
                llOwnerSay(&amp;quot;[&amp;quot;+llList2CSV(rope)+&amp;quot;]== &amp;quot;+llJsonGetValue(j,[i]));&lt;br /&gt;
                //read from your list what json type is at this position and do something with it.&lt;br /&gt;
}}}}&lt;br /&gt;
//Jnested(json,[]);//would print each value of the nexted JSN_ARRAY with its &amp;quot;address list&amp;quot;, that is building up recursively as &amp;quot;rope&amp;quot; that leads you trough the tree/maze.&lt;br /&gt;
 &lt;br /&gt;
//Jnested(j) should be useful to read from large matrices (as in 300x300 fields) that may even contain complex numbers at some places.&lt;br /&gt;
//I tried to read very long JSONs with llGetSubString(), but llGetSubString() too easily stack-heap collides on very long strings,&lt;br /&gt;
//so you have to go trough the nested list using Jnested(j) to read and print it per entry.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|相关函数=&lt;br /&gt;
[[llList2Json]]&lt;br /&gt;
[[llJson2List]]&lt;br /&gt;
[[llJsonSetValue]]&lt;br /&gt;
[[llJsonGetValue]]&lt;br /&gt;
|相关事件=无&lt;br /&gt;
&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Ty</name></author>
		
	</entry>
</feed>