js json是否有value

JavaScript04

js json是否有value,第1张

JSON就是键值对的存储,所以您说的value就是对应一个Key的Value。建议你稍微看下下面的JSON入门教程

JSON教程:http://www.sojson.com/json/ JSON在线解析:http://www.sojson.com/

啊哦,什么语言呢?

我先用Jquery(Javascript)解析给你看。

var json = {"materials":[{"id":"1","name":"abcde","type":"abc","count":"2.6530001163482666","danwei":"kg","energykind":"output"},{"id":"2","name":"abcde","type":"abcd","count":"2.6530001163482666","danwei":"kg","energykind":"output"},{"id":"3","name":"abc","type":"abcd","count":"2.6530001163482666","danwei":"kg","energykind":"output"},{"id":"4","name":"abc","type":"abcd","count":"2.6530001163482666","danwei":"mm","energykind":"input"},{"id":"5","name":"","type":"","count":"25.3","danwei":"","energykind":""},{"id":"6","name":"abcwe","type":"abcaad","count":"96.11100006103516","danwei":"2m","energykind":"we"},{"id":"7","name":"abeeeeec","type":"aaaaabcd","count":"16.652999877929688","danwei":"Gm","energykind":"output"},{"id":"9","name":"ampc","type":"abpedcd","count":"2.653","danwei":"m2","energykind":"input"},{"id":"10","name":"ampc","type":"abpedcd","count":"2.653","danwei":"m2","energykind":"input"},{"id":"11","name":"ampc","type":"abpedcd","count":"2.653","danwei":"m2","energykind":"input"},{"id":"12","name":"amfpc","type":"abperfdcd","count":"72.653","danwei":"f2","energykind":"input"},{"id":"13","name":"bg","type":"hh","count":"2.66","danwei":"jm","energykind":"cg"},{"id":"14","name":"bd","type":"js","count":"2.77","danwei":"dg","energykind":"dk"},{"id":"15","name":"cooal","type":"coal","count":"1.05","danwei":"mg","energykind":"input"}]}

var types = []

$.each(json.materials,function(){

    types.push(this.type)

})

console.log(types)

哦了。你试试,然后你可以用下面的工具看看你的结构。

JSON在线解析:http://www.sojson.com/

JSON在线解析:http://www.sojson.com/simple_json.html