从json

时间:2018-11-29 11:02:55

标签: javascript arrays json

大家好,我是json的新手,我想知道如何在不知道其名称的情况下删除json的所有根元素。有没有办法在不使用JavaScript的情况下删除整个json根的名称?

我拥有的杰森数据:

{
  "ethbtc": {
    "name": "ETH/BTC",
    "base_unit": "eth",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  },
  "trstbtc": {
    "name": "TRST/BTC",
    "base_unit": "trst",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  }
}

我想要的JSON数据

{
  {
    "name": "ETH/BTC",
    "base_unit": "eth",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  },
  {
    "name": "TRST/BTC",
    "base_unit": "trst",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  }
}

谢谢

1 个答案:

答案 0 :(得分:0)

var json={
  "ethbtc": {
    "name": "ETH/BTC",
    "base_unit": "eth",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  },
  "trstbtc": {
    "name": "TRST/BTC",
    "base_unit": "trst",
    "quote_unit": "btc",
    "low": "0.0",
    "high": "0.0",
    "last": "0.0",
    "open": "0.0",
    "volume": 0,
    "amount": "0.0",
    "sell": "0.0",
    "buy": "0.0"
  }
};
console.log(Object.values(json));

使用Object.values。在不知道键值的情况下访问json对象的所有值。