Difference between revisions of "LlJsonGetValue/ja"

From Second Life Wiki
Jump to navigation Jump to search
(copy from english(Todo: need translate to japanese))
 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{LSL Function
{{LSL Function/ja
|inject-2={{Issues/BUG-3692}}
|inject-2={{Issues/BUG-3692}}
|func_id=|func_sleep=0.0|func_energy=10.0
|func_id=|func_sleep=0.0|func_energy=10.0
|func=llJsonGetValue|return_type=string|p1_type=string|p1_name=json|p2_type=list|p2_name=specifiers
|func=llJsonGetValue|return_type=string|p1_type=string|p1_name=json|p2_type=list|p2_name=specifiers
|func_desc=Gets the value indicated by specifiers from the [http://json.org json] string.
|func_desc=[http://json.org JSON] 文字列を表す '''json''' を解析し、'''specifiers''' で指定された方法でトラバースして得られる値を取得します。
|return_text=made by parsing '''json''', a string representing json and traversing as specified by '''specifiers'''.
|return_text=入力が無効であるか、結果が見つからない場合、この関数は [[JSON_INVALID]] を返します。結果が <code>null</code> の場合、関数は [[JSON_NULL]] を返します。
|func_footnote=When the input is invalid or no result can be found this function returns [[JSON_INVALID]]. If the result is <code>null</code> the function returns [[JSON_NULL]].
|spec=[[Json_usage_in_LSL|LSL での JSON の使用]] を参照してください。
|spec=See [[Json_usage_in_LSL|Json usage in LSL]]
|constants
|constants
|caveats=
|caveats=
* Manual definition of JSON syntax within LSL does not always parse in the expected way, so be careful to avoid using syntax characters anywhere other than where needed (for example, inside a string.); alternately escape the syntax character and use [[llUnescapeURL]] on the retrieved string to convert it back - See bugs.
* LSL内でJSON構文を手動で定義すると、常に期待どおりに解析されるわけではないため、必要な場所以外で構文文字を使用しないように注意してください(たとえば、文字列の内部では)。代わりに構文文字をエスケープし、取得した文字列に[[llUnescapeURL]]を使用して変換するとよいです。 - バグに関する情報を参照してください。
{{KBwarning|The below comment in regards to speed is unverified on modern simulator versions, and thus cannot be assumed to be true. '''Always test execution speed claims for yourself.'''}}
{{KBwarning|以下の速度に関するコメントは現代のシミュレータバージョンでは検証されておらず、そのため真実であると仮定することはできません。常に実行速度の主張を自分でテストしてください。}}
* [[llJsonGetValue]] is significantly slower than reading a value from a list with [[llList2String]]. But with [[llList2String]], you will need to parse your string and convert it to list. [[llJsonGetValue]] is significantly faster when you will need to parse your string: for instance by <code>[[llList2String]]([[llParseString2List]]( yourstring, [delimiters], [spacers]), N );</code> When you need to iterate intensively, think about [[llJson2List]].
* [[llJsonGetValue]] [[llList2String]] を使用してリストから値を読み取るよりも遥かに遅いです。ただし、[[llList2String]]を使用する場合、文字列を解析しリストに変換する必要があります。[[llJsonGetValue]]は、文字列を解析する必要がある場合(たとえば、<code>[[llList2String]]([[llParseString2List]](yourstring, [delimiters], [spacers]), N );</code>で)、解析する必要がある場合はかなり高速です。反復処理が必要な場合は、[[llJson2List]]を考えてください。
|examples=
|examples=
<syntaxhighlight lang="lsl2">
<syntaxhighlight lang="lsl2">
Line 54: Line 53:
}
}
</syntaxhighlight>
</syntaxhighlight>
See also [[llJsonValueType]] for examples where the value type is checked before getting the value as that type.
「llJsonValueType」も参照してください。これは、値のタイプが取得する前にそのタイプがチェックされる例がある場所です。
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llList2Json]]|}}
|also_functions={{LSL DefineRow||[[llList2Json]]|}}

Latest revision as of 13:05, 22 November 2023

要約

関数: string llJsonGetValue( string json, list specifiers );

JSON 文字列を表す json を解析し、specifiers で指定された方法でトラバースして得られる値を取得します。
入力が無効であるか、結果が見つからない場合、この関数は JSON_INVALID を返します。結果が null の場合、関数は JSON_NULL を返します。を string で返します。

• string json
• list specifiers

仕様

LSL での JSON の使用 を参照してください。

警告

  • LSL内でJSON構文を手動で定義すると、常に期待どおりに解析されるわけではないため、必要な場所以外で構文文字を使用しないように注意してください(たとえば、文字列の内部では)。代わりに構文文字をエスケープし、取得した文字列にllUnescapeURLを使用して変換するとよいです。 - バグに関する情報を参照してください。
KBwarning.png 警告: 以下の速度に関するコメントは現代のシミュレータバージョンでは検証されておらず、そのため真実であると仮定することはできません。常に実行速度の主張を自分でテストしてください。
  • llJsonGetValuellList2String を使用してリストから値を読み取るよりも遥かに遅いです。ただし、llList2Stringを使用する場合、文字列を解析しリストに変換する必要があります。llJsonGetValueは、文字列を解析する必要がある場合(たとえば、llList2String(llParseString2List(yourstring, [delimiters], [spacers]), N );で)、解析する必要がある場合はかなり高速です。反復処理が必要な場合は、llJson2Listを考えてください。

Important Issues

~ All Issues ~ Search JIRA for related Bugs
   JSON does not correctly handle ] inside strings nested within arrays or } inside strings nested within objects

サンプル

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
    }
}
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.
}
「llJsonValueType」も参照してください。これは、値のタイプが取得する前にそのタイプがチェックされる例がある場所です。

関連項目

関数

•  llList2Json
•  llJson2List
•  llJsonSetValue
•  llJsonValueType

記事

•  Typecast

特記事項

経緯

Date of Release 20/05/2013

All Issues

~ Search JIRA for related Issues
   JSON does not correctly handle ] inside strings nested within arrays or } inside strings nested within objects

Signature

function string llJsonGetValue( string json, list specifiers );
この翻訳は 原文 と比べて古いですか?間違いがありますか?読みにくいですか?みんなで 修正 していきましょう! (手順はこちら)
この項目はあなたにとって参考にならない項目ですか?もしかしたらLSL Wikiの関連した項目が参考になるかもしれません。