将JSON对象数组映射到字符串

编程入门 行业动态 更新时间:2024-10-28 20:23:04
本文介绍了将JSON对象数组映射到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试利用Google SpreadSheets(Google脚本)中的地图功能,使用API​​从Bittrex获取我的帐户硬币余额.这是我的JSON对象:

I'm trying to utilize map function in Google SpreadSheets (Google Script) to get my account coin balances from Bittrex using API. Here is my JSON object:

({success:true, message:"", result:[ {Currency:"BTC", Balance:0.01, Available:0.01, Pending:0, CryptoAddress:null}, {Currency:"ETH", Balance:1.0, Available:1.0, Pending:0, CryptoAddress:null} ]} })

理想情况下,我想根据结果和基础行中的键(使用每个对象的数据)自动填充标题行. 我看到了spme解决方案如何将其用于每种或更复杂的方法.但是我想这可以通过映射来完成.这是我如何映射第一行,但不知道如何映射值:

Ideally I would like to populate header row automatically, based on Keys in result and underlying rows using data from each object. I saw spme solutions how to do that using for each or more complicated way. But I guess this can be done by just mapping. Here is how I mapped top row, but don't know how to map values:

var headerRow = Object.keys(json.result[0]);

Google SpreadSheet中的预期输出为

Expected output in Google SpreadSheet is

____________________________________________________________ | Currency | Balance | Available | Pending | CryptoAddress | |__________________________________________________________| | BTC | 0.01 | 0.01 | 0 | null | | ETH | 1.0 | 1.0 | 0 | null | ____________________________________________________________

推荐答案

我将执行以下操作.因此,您有了密钥,然后就可以检索该值.

I would do the following. So you have the key and then you can retrieve the value.

Object.keys(json.result[0]).map((val) => { console.log(json.result[0][val])})

将其包装在foreach中以对每个结果执行相同的操作.

Wrap that within a foreach to do the same for each result.

希望有帮助

更多推荐

将JSON对象数组映射到字符串

本文发布于:2023-10-23 03:29:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   对象   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!