javascript - 解析错误的 Json Google 脚本

标签 javascript json google-apps-script

我试图弄清楚如何从 json 响应中获取“oid”值,但现在我不知道,这是我第一次使用谷歌脚本。 这是原始的 json 解析响应:

{btcs=0.01000000, orders=[{amount=0.10000000, price=2000.00000000, oid=592589, type=1}], plns=0.00440603}

当我尝试直接从中获取 oid 时,如果我用“orders”解析它,我得到空变量

   oid = raw_data["orders"]; 
   oid = JSON.stringify(oid)
   oid = oid.toString().replace("[", "");
   oid = oid.toString().replace("]", "");

我得到

{"oid":"592589","type":1,"amount":"0.10000000","price":"2000.00000000"},

如果我添加

oid = oid["oid"]; 

对于我解析的“订单”,它仍然是空的,我尝试直接从解析的“订单”中取出 oid,而不替换“[”和“]”,但 oid 变量仍然是空的。

最佳答案

直接访问数组元素:

var oid = raw_data.orders[0].oid;

关于javascript - 解析错误的 Json Google 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21960878/

相关文章:

javascript - 在 Google 表格中使用 fontcolor() 在单元格中返回 HTML

javascript - 使用 await 调用/申请/绑定(bind)

javascript - Ionic 为什么 nativeElement 是 undefined 的?

javascript - 是否需要在 iron-router@1.0.0-pre3 的服务器代码中定义 RouteControllers

javascript - 如何为 ember js 属性同时拥有观察者和 init

javascript 到 JSON 保存动态属性

java - XML 文件转 Json (org.json)

java - RESTFul WebService - 如何将类变量表示为不同的 json 名称

javascript - Google Apps 脚本中的 Dropbox API v2/删除

google-apps-script - 是否可以在 Google Apps 脚本中执行 ImportRange?