Let's suppose that we have this short text file, that describe some
data about a famous fictional character, formatted with JSON syntax:
{
"name": "Donald Duck",
"species": "duck",
"address": {
"address": "Cornelius Coot St., 1313",
"city": "Duckburg",
"state": "Calisota, USA"
}
}
If I need to find a parameter on a first level node, for example
"name", I can write:
Dim objJSON as JSONMBS
objJSON = New JSONMBS(myJSONText)
Dim objFind as JSONMBS = objJSON.FindFirstLabel("species")
MsgBox("Parameter """ + objFind.Text + """ is: """ +
str(objFind.ChildNode.Text) + """.")
// Outputs: Parameter "species" is: "duck"
But what can I do when I want to find a parameter on a second level
node or else? For example if I need to fetch the value for the
parameter "state" that is actually nested into "address" I'm actually
using:
Dim objJSON as JSONMBS
objJSON = New JSONMBS(myJSONText)
Dim objFind As JSONMBS = objJSON.FindFirstLabel("address")
Dim objFind2 As JSONMBS = objFind.Childnode.FindFirstLabel("state")
MsgBox("Parameter """ + objFind2.Text + """ is: """ +
str(objFind2.ChildNode.Text) + """.")
// Outputs: Parameter "state" is: "Calisota, USA".
Is this the only way to access a nested parameter?
If this is the case and it's not too much work to get this
implemented, in one of the next MBS releases would it be possible to
add an overload to the function "FindFirstLabel", in order to accept a
second boolean parameter to specify if you want to make a recursive
search through all the nodes? If there are more than one node with the
same name IMHO the plugin should always report just the first
occurrence.
For example:
Dim objFindNode AS JSONMBS = objJSON.FindFirstLabel("state", True)
MsgBox("Parameter """ + objFind2.Text + """ is: """ +
str(objFind2.ChildNode.Text) + """.")
// Outputs: Parameter "state" is: "Calisota, USA".
I know that this way the code is more or less of the same size as the
previous code, but IMHO it's far more readable.
What do you think about this feature request?
Best regards
_______________________________________________
Mbsplugins_monkeybreadsoftware.info mailing list
[email protected]
https://ml01.ispgateway.de/mailman/listinfo/mbsplugins_monkeybreadsoftware.info