从js中的json数据格式中检索值

时间:2017-04-11 04:44:51

标签: javascript

以json格式输出

[{
  "school_id": "248",
  "server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/",
  "school_id_string": "jayanagar",
  "logo_path": "0",
  "about": "all"
}]

如何在js中检索 school_id 的值?

4 个答案:

答案 0 :(得分:0)

你首先要解析json:

var obj = JSON.parse("...you json string here");
// This will return you the school id of the fisrt entry of your array.
var school_id = obj[0].school_id;

答案 1 :(得分:0)

您可以使用:

git commit -c user.name=xxx -c user.email=yyy commit -m "my commit"

如果数组中有一个对象,则可以将其let data = [{ "school_id": "248", "server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/", "school_id_string": "jayanagar", "logo_path": "0", "about": "all" }]; console.log(data[0].school_id); // use this if just one object in array console.log(`-----------------------------------------------`) data.forEach(o=>console.log(o.school_id)); // use this if more than one objects in array索引作为目标,以获得目标对象的所需属性。否则,如果有多个对象,则必须遍历每个对象。

答案 2 :(得分:0)

双向

let data = [{"school_id":"248","server_url":"http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/","school_id_string":"jayanagar","logo_path":"0","about":"all"}];

之一:

data[0].school_id

2

data[0]['school_id']

答案 3 :(得分:0)

这将从你的JSON

获得你的schoolid

var t = JSON.parse('{"school_id": "248", "server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/", "school_id_string": "jayanagar", "logo_path": "0", "about": "all"}');
alert(t['school_id'])