我有此JSON数据。我想使用CoffeeScript解析它。 如何获取答案的值?
{"options": [{"answer": "Description for xss injection is", "answer_options": 0, "answer_lang": null}]}
我尝试了这种方法,但是失败了:
for key,value of data
for k,v in value
res.send "#{v}"
答案 0 :(得分:0)
我努力尝试并获得了此解决方案。和它的问题:D
body={"options": [{"answer": "Description for xss injection is","answer_options":0, "answer_lang": null}]}
data=JSON.parse(body);
for i of data.options
counter = data.options[i];
res.send "#{i} #{counter.answer}";
希望,它可以帮助某人:D
答案 1 :(得分:0)
假设json对象存储在一个名为“ object”的变量中:
answer = object["options"][0]["answer"] //answer = "Description for xss injection is"
另一种访问方式:
answer = object.options[0].answer