json_to_dictT_json_to_dictJsonToDictJsonToDictjson_to_dict (Operator)
Name
json_to_dictT_json_to_dictJsonToDictJsonToDictjson_to_dict
— Transform a JSON string into a dictionary.
Signature
void JsonToDict(const HTuple& JsonString, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DictHandle)
static HDictArray HDict::JsonToDict(const HTuple& JsonString, const HTuple& GenParamName, const HTuple& GenParamValue)
void HDict::JsonToDict(const HString& JsonString, const HString& GenParamName, const HString& GenParamValue)
void HDict::JsonToDict(const char* JsonString, const char* GenParamName, const char* GenParamValue)
void HDict::JsonToDict(const wchar_t* JsonString, const wchar_t* GenParamName, const wchar_t* GenParamValue)
(
Windows only)
Description
json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict
transforms the string passed in JsonStringJsonStringJsonStringjsonStringjson_string
,
which must be valid JSON, into a dictionary and returns the handle of
the dictionary in DictHandleDictHandleDictHandledictHandledict_handle
.
Several optional parameters can be set that control the values of
JSON constants. Those parameters can be set via GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name
and GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value
and are described in the documentation of
read_dictread_dictReadDictReadDictread_dict
.
json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict
can transform several strings at once.
For this, JsonStringJsonStringJsonStringjsonStringjson_string
must contain a tuple of strings.
The output DictHandleDictHandleDictHandledictHandledict_handle
will then contain one dictionary
per input string.
Execution Information
- Multithreading type: independent (runs in parallel even with exclusive operators).
- Multithreading scope: global (may be called from any thread).
- Processed without parallelization.
This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.
Parameters
JsonStringJsonStringJsonStringjsonStringjson_string
(input_control) string(-array) →
HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
String in JSON format.
Default:
['{"key":"value"}']
["{"key":"value"}"]
["{"key":"value"}"]
["{"key":"value"}"]
["{"key":"value"}"]
GenParamNameGenParamNameGenParamNamegenParamNamegen_param_name
(input_control) attribute.name(-array) →
HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Name of the generic parameter.
Default:
[]
List of values:
'convert_json_arrays_to'"convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to", 'json_value_false'"json_value_false""json_value_false""json_value_false""json_value_false", 'json_value_null'"json_value_null""json_value_null""json_value_null""json_value_null", 'json_value_true'"json_value_true""json_value_true""json_value_true""json_value_true"
GenParamValueGenParamValueGenParamValuegenParamValuegen_param_value
(input_control) attribute.name(-array) →
HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)
Value of the generic parameter.
Default:
[]
Suggested values:
0, 1, 'HNULL'"HNULL""HNULL""HNULL""HNULL", 'true'"true""true""true""true", 'false'"false""false""false""false", 'dict'"dict""dict""dict""dict", 'tuple'"tuple""tuple""tuple""tuple", 'tuple_if_possible'"tuple_if_possible""tuple_if_possible""tuple_if_possible""tuple_if_possible"
DictHandleDictHandleDictHandledictHandledict_handle
(output_control) dict(-array) →
HDict, HTupleSequence[HHandle]HTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Dictionary handle.
Example (HDevelop)
json_to_dict ('{"capacity": "medium", "image_height": 1024, "image_width": 1024}', [], [], DictHandle)
Result
If the parameters are valid, the operator json_to_dictjson_to_dictJsonToDictJsonToDictjson_to_dict
returns
the value 2 (
H_MSG_TRUE)
. If necessary an exception is raised.
This is especially the case if JsonStringJsonStringJsonStringjsonStringjson_string
does not contain
valid JSON.
Possible Successors
write_dictwrite_dictWriteDictWriteDictwrite_dict
,
copy_dictcopy_dictCopyDictCopyDictcopy_dict
Alternatives
read_dictread_dictReadDictReadDictread_dict
,
create_dictcreate_dictCreateDictCreateDictcreate_dict
See also
read_dictread_dictReadDictReadDictread_dict
,
write_dictwrite_dictWriteDictWriteDictwrite_dict
,
serialize_handleserialize_handleSerializeHandleSerializeHandleserialize_handle
,
deserialize_handledeserialize_handleDeserializeHandleDeserializeHandledeserialize_handle
Module
Foundation