Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Get the value of a key containing a string by traversing the JSON key-value pair _ an introduction to computer programming tutorial self-study

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report