Is there any chance to convert input json string (with dynamic data - such as any names of variables and any number of this variables, mixed with arrays with same properties - any number of variableth with any names) and objects containing such things?
This variable must be like php variables with associative names or something like this to easy acces to any part of that variable? Is this possible? I'm breaking my head more than a week to understand how to do this and i'm at the beginning every time.
Just for example, two json strings that can come (it's only examples, incoming json strings can be any mix of arrays/objects/data and i formatted it to easy reading with crlf's/spaces):
JSON example #1 (object with array with numbers/string/arrays[/objects])
Code: Select all
[
{
"var1_name": value1_flo_or_int,
"var2_name": "some string",
"var3_named_array": {
"arrvar1": value_arrvar1_flo_or_int,
"arrvar2": "string"
},
"var4_name": value4_flo_or_int
}
]
Code: Select all
{
"var1_named_array": {
"arrvar1": value_arrvar1_flo_or_int,
"arrvar2": "string"
},
"var2_name": "some string",
"var3_name": value3_flo_or_int,
"var4_named_array": {
"arrvar1": value_arrvar1_flo_or_int,
"arrvar2": value_arrvar2_flo_or_int,
"arrvar3": "string"
},
"var5_name": value5_flo_or_int
}
for JSON input #1
debug "'" + json_decoded_var\var2_name + "'" ; will be 'some string'
debug "'" + json_decoded_var\var3_named_array('arrvar1') + "'" ; will be 'value_arrvar1_flo_or_int'
Or maybe "json_decoded_var.var3_named_array.arrvar1" to access. Just named access, how it will be done - by "\" like structure or by "." - it does not matter.
And i think it's important that variables inside variables can be sorted.
I tried to make Structured object with procedure that recursively calls itself when inner variable is object or array without any luch. I'm still novice in pb and can't understand some things and just stuck in a simple or maybe little moderate question.
In php it's simple as we breathe. In pb i can't understand how to do this.

Please, help me understand it and finish it. I want to learn pb, but stuck. "Just lost in the three pines".
At the end i want to do #1 or #2
Code: Select all
ParseResult = ParseJSON(0, InputString$)
If ParseResullt
ParseValue = JSONValue(0)
ParseResult = ProcedureThatConvertsJSONStringToVariable(ParseValue, myNewVariableWithParsedJSON)
;ParseResult is the 1 = success or 0 = fail
ElseIf
; error in parsing
End
Code: Select all
ParseResult = ParseJSON(0, InputString$)
If ParseResullt
ParseValue = JSONValue(0)
myNewVariableWithParsedJSON = ProcedureThatConvertsJSONStringToVariable(ParseValue)
;myNewVariableWithParsedJSON - just a result of converting input json string to variable
ElseIf
; error in parsing
End