Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil) . Junte-se a nós e ajude a fazer o trabalho!
nsISupports
Last changed in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)legacyDecodeToJSVal()
method. However, you should use native JSON instead if at all possible.Implemented by: @mozilla.org/dom/json;1
. To create an instance, use:
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"] .createInstance(Components.interfaces.nsIJSON);
Method overview
JSObject decode(in AString str ); Obsolete since Gecko 7.0 |
jsval decodeToJSVal(in AString str, in JSContext cx); Native code only! |
JSObject decodeFromStream(in ); |
AString encode(in JSObject value ); Obsolete since Gecko 7.0 |
AString encodeFromJSVal(in Jsvaljsval value , in JSContext cx); Native code only! |
void encodeToStream(in JSObject value ); |
jsval legacyDecode(in AString str); Deprecated since Gecko 2.0 |
jsval legacyDecodeFromStream(in AString str); Deprecated since Gecko 2.0 |
jsval legacyDecodeToJSVal(in AString str, in JSContext cx); Native code only! Deprecated since Gecko 2.0 |
Methods
decode()
Decodes a JSON string, returning the JavaScript object it represents.
JSObject decode( in AString str );
Parameters
str
- The JSON string to decode.
Return value
The original JavaScript object, reconstructed from the JSON string.
decodeToJSVal()
jsval
for use in your native code. Don't forget to GCroot the result before using it.jsval decodeToJSVal( in AString str, in JSContext cx );
Parameters
str
- The JSON string to decode.
- cx
- The JavaScript runtime context to use to decode the string.
Return value
The original JavaScript object, reconstructed from the JSON string. Don't forget to GCroot the jsval
before using it.
decodeFromStream()
Decodes a JSON string read from an input stream, returning the JavaScript object it represents.
JSObject decodeFromStream( in nsIInputStream stream, in long contentLength );
Parameters
stream
- The
nsIInputStream
from which to read the JSON string. contentLength
- The length of the JSON string to read.
Return value
A JSObject
which is the original JavaScript object, reconstructed from the JSON string.
encode()
Encodes a JavaScript object into a JSON string.
AString encode( in JSObject value );
Parameters
value
- The JavaScript object to encode.
Return value
A JSON string representing the object.
encodeFromJSVal()
jsval
to a JSON string for use in your native code.AString encodeFromJSVal( in jsval value, in JSContext cx );
Parameters
value
- A pointer to the jsval to encode.
- cx
- The JavaScript runtime context to use to encode the value.
Return value
A JSON string representing the value.
encodeToStream()
Encodes a JavaScript object into JSON format, writing it to a stream.
void encodeToStream( in nsIOutputStream stream, in string charset, in boolean writeBOM in JSObject value );
Parameters
stream
- The
nsIOutputStream
to which to write the JSON string. charset
- The string encoding to use. Only the five Unicode encodings "UTF-8", "UTF-16LE", "UTF-16BE", "UTF-32LE" and "UTF-32BE" are supported.
writeBOM
- Specify
true
if you wish to write a byte-order mark (BOM) into the stream, otherwise specifyfalse
. value
- The JavaScript object to encode.
legacyDecode()
Deprecated
This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
Decodes a JSON string. This method accepts slightly more than the exact JSON syntax; details of extra accepted syntax are deliberately not described. This method is intended for use only by code processing legacy data. When the original instance requiring this function is removed, this method will be removed. Thus, this deprecated method should not be used.
jsval legacyDecode( in AString str );
Parameters
str
- The JSON string to decode.
Return value
The original JavaScript object, reconstructed from the JSON string.
legacyDecodeFromStream()
Deprecated
This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
Decodes a JSON string, read from a stream. This method accepts slightly more than the exact JSON syntax; details of extra accepted syntax are deliberately not described. This method is intended for use only by code processing legacy data. When the original instance requiring this function is removed, this method will be removed. Thus, this deprecated method should not be used.
jsval legacyDecodeFromStream( in nsIInputStream stream, in long contentLength );
Parameters
stream
- The
nsIInputStream
from which to read the JSON string to decode. contentLength
- The length of the string to decode.
Return value
The original JavaScript object, reconstructed from the JSON string.
legacyDecodeToJSVal()
Deprecated
This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
Decodes a JSON string to a jsval. This method accepts slightly more than the exact JSON syntax; details of extra accepted syntax are deliberately not described. This method is intended for use only by code processing legacy data. When the original instance requiring this function is removed, this method will be removed. Thus, this deprecated method should not be used.
jsval
for use in your native code. Don't forget to GCroot the result before using it.jsval legacyDecodeToJSVal( in AString str, in JSContext cx );
Parameters
str
- The JSON string to decode.
- cx
- The JavaScript runtime context to use to decode the string.
Return value
The original JavaScript object, reconstructed from the JSON string. Don't forget to GCroot the jsval
before using it.