简体   繁体   English

JSON 解析 Javascript 未定义数据

[英]JSON PARSE Javascript undefined data

This is the code + json data这是代码 + json 数据

const json = '{"success": true, "transactions": [{"additions": [{"amount": 100, "parent_coin_info": "0x494c45f1fadaf192dee4af43f70d9ce30a22fd5dba8dc56c192ad6cb95a6f0e3", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 100, "confirmed": true, "confirmed_at_height": 695392, "created_at_time": 1628590091, "fee_amount": 0, "memos": {}, "name": "0xc369519132fe24a20eeb38a76cd7a8dd08052e31366614890a5b244d50f8f862", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 2267000000000, "parent_coin_info": "0xa73135e073f60d57a6ae091a84ae333c4986c566bc28be24db97c6e57e8a48f0", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 2267000000000, "confirmed": true, "confirmed_at_height": 695404, "created_at_time": 1628590217, "fee_amount": 0, "memos": {}, "name": "0xe244fb3af844467cd289993ffa5b5d6d9708a3d42dc550c86731bce049ac5d49", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 7185000000000, "parent_coin_info": "0x58860366eff83d4b05551746353c106dd4725818ef22ebc24e3e40da7c68a875", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 7185000000000, "confirmed": true, "confirmed_at_height": 792209, "created_at_time": 1630396455, "fee_amount": 0, "memos": {}, "name": "0x70c2c0ebcdadbb7f2a58f99b1de671f8d00bf32ac05a69e3e4c3c2786b66cb33", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 309000000000, "parent_coin_info": "0x3c102d12f0637d159c81d0dbca3b22dcfbb10406211651fcdbbaec6b59432eaf", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 309000000000, "confirmed": true, "confirmed_at_height": 799903, "created_at_time": 1630542840, "fee_amount": 0, "memos": {}, "name": "0x4087bac21de2707e174ad6219008ecfc6001bef5b1deb4b48add0634b522e952", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 224649680000, "parent_coin_info": "0xcb641b8eaa28d46b6ae2c1412197a85ba205fae715ee130971a06c264d47205c", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 224649680000, "confirmed": true, "confirmed_at_height": 842629, "created_at_time": 1631335948, "fee_amount": 0, "memos": {}, "name": "0x6eb1f92ced3c407cee0906c310244b58a646c0ac87f2ed29f6c806dc3f4f2b26", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 5534000000000, "parent_coin_info": "0x6b42d6c127570cf223f56ddf1060900fd28b69975893b4f64cf39484e6879aae", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 5534000000000, "confirmed": true, "confirmed_at_height": 864455, "created_at_time": 1631744868, "fee_amount": 0, "memos": {}, "name": "0x13a184a3212b1045fb3799896aa497d4a5791fb4ccab7a2808f72f0f2f9cf195", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 662232040000, "parent_coin_info": "0x579a9c9ce56437600156233315a1d220633c111f759c9f68b8cf927396f6d552", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 662232040000, "confirmed": true, "confirmed_at_height": 1009934, "created_at_time": 1634465614, "fee_amount": 0, "memos": {}, "name": "0x7b16ba28f02a17d7e800a8ec365909ff99e8b1c026a2f32c7e0d71d013d63cb2", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 1730000000000, "parent_coin_info": "0xc64fc9a5046efc69ceca75cd554d8d4cf4be078a3cd1fbfa01b09356303d6733", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 1730000000000, "confirmed": true, "confirmed_at_height": 1112406, "created_at_time": 1636382957, "fee_amount": 0, "memos": {}, "name": "0x58ae6b8cd6312724ec05a8ec1337b86ec5fea0c357c0ad22a1573f5d1c36655d", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 568094810000, "parent_coin_info": "0x9958c3fd892f76f149331e47afe5a2c480838ec9fab59310d6ce979e0b8b70b2", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 568094810000, "confirmed": true, "confirmed_at_height": 1128704, "created_at_time": 1636690001, "fee_amount": 0, "memos": {}, "name": "0x1a223c94b31af578b73ed88034ba79ea7724b8fd2c6ade1fb84a56aa4f65be3b", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 423625160000, "parent_coin_info": "0x687e619671330bbd1b5fab39f1c32e5dcad6d1fad6c8607c9381d4a66a6c304f", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 423625160000, "confirmed": true, "confirmed_at_height": 1216498, "created_at_time": 1638332958, "fee_amount": 0, "memos": {}, "name": "0x7ecd63440654a1324a173fbf30012fba94555563765f218d167deb2052924f4b", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 7183999999900, "parent_coin_info": "0xd59ad7da8d997ce78b7cf47ae1f37072f685f2e358d5e399675345b564053f26", "puzzle_hash": "0x60f2cfa299bbf5a6edf7a24f2223af283155e51faed440b2ae53be57dce49684"}, {"amount": 1000000000, "parent_coin_info": "0xd59ad7da8d997ce78b7cf47ae1f37072f685f2e358d5e399675345b564053f26", "puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25"}], "amount": 1000000000, "confirmed": true, "confirmed_at_height": 1294215, "created_at_time": 1639790032, "fee_amount": 100, "memos": {}, "name": "0xdb5242fb3afdc510fee34bf1dbf1cc2058503a3fac95888562b7e94931eba190", "removals": [{"amount": 7185000000000, "parent_coin_info": "0x58860366eff83d4b05551746353c106dd4725818ef22ebc24e3e40da7c68a875", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch127cflfrxapm0a5r2d9ashqhzx7kczsj04qyalrrlg8aulnrlesjs3w9u09", "to_puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25", "trade_id": null, "type": 1, "wallet_id": 1}, {"additions": [{"amount": 1, "parent_coin_info": "0x5ea0f5a866c9275732b5a3bcd4c7976e072a41c01a6aee0141d1b8d2f13a3f0a", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 1, "confirmed": true, "confirmed_at_height": 1294217, "created_at_time": 1639790107, "fee_amount": 0, "memos": {}, "name": "0xc12601b5260e864afa297b136656ad3531f106f1e629ed46c4370122ef919be9", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 7182999999800, "parent_coin_info": "0x5a1b03efd578c232bc8428f6d00be769180db11a7a48383e4d778bac9bba1c68", "puzzle_hash": "0x4ef747ef9a9ecd9cba4821775385e39334853c0d6182af4d1ee5012b74f28607"}, {"amount": 1000000000, "parent_coin_info": "0x5a1b03efd578c232bc8428f6d00be769180db11a7a48383e4d778bac9bba1c68", "puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25"}], "amount": 1000000000, "confirmed": true, "confirmed_at_height": 1294228, "created_at_time": 1639790430, "fee_amount": 100, "memos": {}, "name": "0x834843586e6cbfd94e74a2d1fc7dfdf83c8fb60f22efc2900b7c62a14b588af9", "removals": [{"amount": 7183999999900, "parent_coin_info": "0xd59ad7da8d997ce78b7cf47ae1f37072f685f2e358d5e399675345b564053f26", "puzzle_hash": "0x60f2cfa299bbf5a6edf7a24f2223af283155e51faed440b2ae53be57dce49684"}], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch127cflfrxapm0a5r2d9ashqhzx7kczsj04qyalrrlg8aulnrlesjs3w9u09", "to_puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25", "trade_id": null, "type": 1, "wallet_id": 1}, {"additions": [{"amount": 1960000000, "parent_coin_info": "0x5b21f7077ac12003c51da6ff8e4b2acb3703f1b44abf4ae7091e9c0adcffb07b", "puzzle_hash": "0x60f2cfa299bbf5a6edf7a24f2223af283155e51faed440b2ae53be57dce49684"}], "amount": 1960000000, "confirmed": true, "confirmed_at_height": 1294237, "created_at_time": 1639790521, "fee_amount": 0, "memos": {}, "name": "0xab5954c30d4281db4fde17a714821682b70b71c1c8a3876947ed5ac03f452c55", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1vrevlg5eh066dm0h5f8jyga09qc4tegl4m2ypv4w2wl90h8yj6zqkekyad", "to_puzzle_hash": "0x60f2cfa299bbf5a6edf7a24f2223af283155e51faed440b2ae53be57dce49684", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 3000000000, "parent_coin_info": "0x044a9fb602809e54f68b9562caeab105f93aaf05bb2f141887e49d81026bef59", "puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25"}, {"amount": 7179999999700, "parent_coin_info": "0x044a9fb602809e54f68b9562caeab105f93aaf05bb2f141887e49d81026bef59", "puzzle_hash": "0x3cdebe1d204689d112a49770a5ec78aaa9051856d11ef9c12735026809f63259"}], "amount": 3000000000, "confirmed": true, "confirmed_at_height": 1294248, "created_at_time": 1639790675, "fee_amount": 100, "memos": {}, "name": "0x8dbcf2bbce10b0259bfc3a634ed54aef6157af45f2e8fb8d6f6734cef1e300be", "removals": [{"amount": 7182999999800, "parent_coin_info": "0x5a1b03efd578c232bc8428f6d00be769180db11a7a48383e4d778bac9bba1c68", "puzzle_hash": "0x4ef747ef9a9ecd9cba4821775385e39334853c0d6182af4d1ee5012b74f28607"}], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch127cflfrxapm0a5r2d9ashqhzx7kczsj04qyalrrlg8aulnrlesjs3w9u09", "to_puzzle_hash": "0x57b09fa466e876fed06a697b0b82e237ad81424fa809df8c7f41fbcfcc7fcc25", "trade_id": null, "type": 1, "wallet_id": 1}, {"additions": [{"amount": 5880000000, "parent_coin_info": "0xfa634c705272fc5fc77b85533c042742d751cee82e377d5bf4ecf6c94791236b", "puzzle_hash": "0x4ef747ef9a9ecd9cba4821775385e39334853c0d6182af4d1ee5012b74f28607"}], "amount": 5880000000, "confirmed": true, "confirmed_at_height": 1294253, "created_at_time": 1639790795, "fee_amount": 0, "memos": {}, "name": "0xdd6ecd5fa33397a5a66ae73057e493180b2abd0e286263e6c21d177ec5cd2644", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1fmm50mu6nmxeewjgy9m48p0rjv6g20qdvxp27ng7u5qjka8jscrsthqp5z", "to_puzzle_hash": "0x4ef747ef9a9ecd9cba4821775385e39334853c0d6182af4d1ee5012b74f28607", "trade_id": null, "type": 0, "wallet_id": 1}, {"additions": [{"amount": 720996620000, "parent_coin_info": "0x6b12360bef830655d0b50d826678c5405064c9c16c0622adac53d2bd97bd29d7", "puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b"}], "amount": 720996620000, "confirmed": true, "confirmed_at_height": 1364239, "created_at_time": 1641103898, "fee_amount": 0, "memos": {}, "name": "0x4a93d284faafd283dbb20db2a6192fc29fd2f49e467f8ac7e7546eba5ccc78ba", "removals": [], "sent": 0, "sent_to": [], "spend_bundle": null, "to_address": "xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5", "to_puzzle_hash": "0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b", "trade_id": null, "type": 0, "wallet_id": 1}], "wallet_id": 1}';
const obj = JSON.parse(json);

console.log(obj.transactions);

and this is the output.这是 output。


[ { additions: [ [Object] ],
    amount: 100,
    confirmed: true,
    confirmed_at_height: 695392,
    created_at_time: 1628590091,
    fee_amount: 0,
    memos: {},
    name:
     '0xc369519132fe24a20eeb38a76cd7a8dd08052e31366614890a5b244d50f8f862',
    removals: [],
    sent: 0,
    sent_to: [],
    spend_bundle: null,
    to_address:
     'xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5',
    to_puzzle_hash:
     '0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b',
    trade_id: null,
    type: 0,
    wallet_id: 1 },
  { additions: [ [Object] ],
    amount: 2267000000000,
    confirmed: true,
    confirmed_at_height: 695404,
    created_at_time: 1628590217,
    fee_amount: 0,
    memos: {},
    name:
     '0xe244fb3af844467cd289993ffa5b5d6d9708a3d42dc550c86731bce049ac5d49',
    removals: [],
    sent: 0,
    sent_to: [],
    spend_bundle: null,
    to_address:
     'xch1lmlke8cqqx8hehgjwy0km9a3m55rxhmfkht78r55ywm9h5wtjxds6jq6e5',
    to_puzzle_hash:
     '0xfeff6c9f00018f7cdd12711f6d97b1dd28335f69b5d7e38e9423b65bd1cb919b',
    trade_id: null,
    type: 0,
    wallet_id: 1 }

going like that


How can I get amount from json data?如何从 json 数据中获取金额? I am getting data with curl and saving as txt.我正在使用 curl 获取数据并保存为 txt。 I want to parse this json data.我想解析这个 json 数据。

obj.transactions.amount is says undefined obj.transactions.amount 表示未定义

transactions is an array. transactions是一个数组。 If, for example, you want to access the first object's amount , you need to access obj.transactions[0].amount .例如,如果您想访问第一个对象的amount ,则需要访问obj.transactions[0].amount Or if you want to gather all the amount s, you could use a map :或者,如果您想收集所有amount ,可以使用map

const amounts = obj.transactions.map((transaction) => transaction.amount);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM