Get the value of a key containing a string by traversing the JSON key-value pair _ an introduction to computer programming tutorial self-study
First published in: Aardio by traversing the JSON key-value pair to get the value of the key containing a string _ introduction to computer programming tutorial self-study
Http://jianma123.com/viewthread.aardio?threadid=429
Sometimes the key name in the JSON object changes
But every time there is a pattern of change.
Contains a specific string prefix
So if you want to get its value, but
By traversing key-value pairs
If it is determined that the key name contains a specific string, the value of the key is taken out.
The source code is as follows
Import console
Var str = / / {"value": {"element-6066-11e4-a52e-4f735466cecf": "cb830670-0e36-4593-96c8-e119febcb0a1"}}
Import web.json
Var tab = web.json.parse (str)
Var the value you want to take = ""
For (KJO v in tab.value) {
/ / console.log (kpene v)
If (string.find (k, "element")) {
/ / console.log (v)
The value you want to take is v
}
}
Console.log (the value you want)
Console.pause (true)