【问题标题】:parse json in coffee script在咖啡脚本中解析 json
【发布时间】:2018-12-30 13:59:41
【问题描述】:

我有这个 JSON 数据。我想用 CoffeeScript 解析它。 如何获取 answer 的值?

{"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}"

【问题讨论】:

    标签: json parsing coffeescript


    【解决方案1】:

    我很努力,得到了这个解决方案。及其工作: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

    【讨论】:

      【解决方案2】:

      假设 json 对象存储在一个名为“object”的变量中:

      answer = object["options"][0]["answer"] //answer = "Description for xss injection is"
      

      另一种访问方式:

      answer = object.options[0].answer
      

      【讨论】:

        猜你喜欢
        • 2013-06-25
        • 2013-06-10
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 2015-12-12
        • 2013-01-09
        相关资源
        最近更新 更多