JSON解析集字符串

时间:2017-11-22 21:27:16

标签: json

我正在尝试阅读JSON数据度量并更新表

var obj = JSON.parse('{"id": "cgk3",  "measures": [[38, 983]],"sid": 30, "did": "dgk1"}');

var conn = $.db.getConnection();
conn.prepareStatement("SET SCHEMA \"xyz\"").execute();

var st = conn.prepareStatement("INSERT INTO \"123\" values(?,?,?)");

st.setString(1, obj.id);
st.setInt(2, obj.measures[1]);    // Whats wrong in here I need toinsert first measure into the table..I mean how to read if the measures comes in like that
st.setString(3, obj.did);

st.execute();

提前致谢

1 个答案:

答案 0 :(得分:0)

您正在尝试访问不在"度量"中的索引。 Measures包含一个数组数组,您需要访问这样的元素:

console.log(obj.measures[0][0]);
console.log(obj.measures[0][1]);