查看“LlJsonGetValue”的源代码
←
LlJsonGetValue
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}} {{函数详情 |函数名 = Function: string llJsonGetValue( string json, list specifiers ); |参数= 参数: string json list specifiers |返回值= 返回值:返回一个通过解析 json 生成的字符串,这个字符串表示 json 并按说明符的指定进行遍历 |注意事项=Lljsongetvalue 要比从带有 lllist2string 的列表读取值慢得多。但是使用 lllist2string 时,需要解析字符串并将其转换为 list。当您需要解析字符串时,lljsongetvalue 要快得多: 例如,通过 lllist2string (llparsestring2list (yourstring,[ delimiters ] ,[ spacers ]) ,n) ; 当您需要集中地迭代时,考虑 lljson2list。 |示例= 示例一 <pre> default { state_entry() { //below is an example of a JSON=string with a key called "key" and a value "val" string json1 = "{\"key\":\"val\"}"; llSay(0, llJsonGetValue( json1, ["key"]));//returns "val" in localchat string json2 = "{\"mansBestFriend\":\"dog\"}"; llSay(0, llJsonGetValue( json2, ["mansBestFriend"]));//returns "dog" in localchat } } </pre> 示例二 <pre> JGetValTest(){ string j="[[1,2],[4,5,6]]"; //JSON may be written directly as a string like this in sl. string k; //this will change with each command below; k=llJsonGetValue(j,[]); //returns the whole array of a JSON. It might just be one entry or a whole nested array or whole nested object. //if "j" is a single JSON_STRING, this may return what the string represents as a JSON within a string; a JSON_NUMBER , JSON_TRUE, TRUE ... k=llJsonGetValue("\"3.14\"",[]); //==k="3,14" (float that was stored in a JSON_STRING within a JSON. and not as JSON_NUMBER for no good reason) k=llJsonGetValue("\"TRUE\"" ,[]); //==k="TRUE" (the value was stored as a JSON_STRING and is thus returned verbatim) k=llJsonGetValue(j,[0]); //returns only the first entry (at offset 0). An entry can be any JSON type, //each entry being separated by a comma from other entries. //array and object entries may contain multiple comma separated entries within them. k=llJsonGetValue(j,[1]);//returns only the second entry... (all the above still applies) k="[4,5,6]"; k=llJsonGetValue(llJsonGetValue(j,[1]),[2]); //instead of getting an entry from "j" we get a sub-entry from llJsonGetValue(j,[1]), //assuming the sub-entry is a JSON_ARRAY. It returns the 3rd sub-entry of the second entry, //that is an array with 3 entries. it would make k="6". //it will return JSON_INVALID if there is no 3rd entry in the 2nd sub-array, //or no 2nd sub-array. k=llJsonGetValue(j,[1,2]); //Shorter way to do the same as in the previous example. k=llJsonGetValue("true",[]); //Sets k to JSON_TRUE k=llJsonGetValue("True",[]); //Sets k to JSON_INVALID because the JSON constant for 'true' is all lower case k=llJsonGetValue("TRUE",[]); //Sets k to JSON_INVALID because the JSON constant for 'true' is all lower case k=llJsonGetValue(JSON_TRUE,[]); //Sets k to JSON_INVALID. The JSON_xxxx constants are not supposed to be part of // a JSON string, just values to test against. } </pre> |相关函数= [[llList2Json]] [[llJson2List]] [[llJsonSetValue]] [[llJsonValueType]] |相关事件=无 }}
该页面使用的模板:
模板:LSL Header
(
查看源代码
)
模板:LSLC
(
查看源代码
)
模板:LSLGC
(
查看源代码
)
模板:Multi-lang
(
查看源代码
)
模板:函数详情
(
查看源代码
)
返回至
LlJsonGetValue
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
网站首页
知识百科
编辑帮助
最近更改
工具
链入页面
相关更改
特殊页面
页面信息