且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 CoffeeScript 中从 JSON 中获取数据?

更新时间:2023-08-26 12:21:28

你是否在 browser 或在 Node 中,您应该能够将 JSON 字符串传递给 JSON.parse并挑选出你想要的价值.然后,您可以使用 Node 的 fs 模块附加到文件,如下所示:https://***.com/a/11267583/659910.

Whether you're doing this in the browser or in Node, you should be able to pass the JSON string to JSON.parse and pick out the value you want. You can then append to a file using Node's fs module like this: https://***.com/a/11267583/659910.

fs = require 'fs'

# Sample JSON string.
json = '{ "statType": "TOTAL_SESSIONS_PLAYED", "count": { "value": 5 }, "dataVersion": 0 }'

data = JSON.parse(json)
fs.appendFile('/tmp/data.txt', data.count.value, (error) -> throw error if error)