亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Javascript中打印json的特定部分?

如何在Javascript中打印json的特定部分?

胡說叔叔 2022-10-27 16:03:10
我有一個 json,可在https://imgur.com/a/F3kV29F 或此處查看https://dweet.io/get/dweets/for/shyam__5在 python 中,我可以通過執行以下操作打印 yearlyWatts:print(collection[1]['content']['yearlyWatts'])其中collection是json,由:collection = (dweepy.get_dweets_for('shyam__5'))我正在嘗試在 Javascript 中做同樣的事情。目前,我已經做了:getCryptoCurrencyInfo(5)     .then(currencyInfo => {             console.log(currencyInfo[1].yearlyWatts)這不起作用,我沒有輸出。請不要關注函數 getCryptoCurrencyInfo,如果有人能告訴我在 console.log(HERE) 中寫什么以輸出 111255.51 的年瓦數,我將不勝感激任何幫助,將不勝感激。謝謝!
查看完整描述

3 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

假設您想要一個年瓦特。


const data = {

    "this": "succeeded",

    "by": "getting",

    "the": "dweets",

    "with": [{

            "thing": "shyam__5",

            "created": "2020-07-03T08:38:01.184Z",

            "content": {

                "test": "test"

            }

        },

        {

            "thing": "shyam__5",

            "created": "2020-07-03T08:37:58.068Z",

            "content": {

                "yearlyWatts": 111429.4

            }

        }

    ]

}


console.log(data.with[1].content.yearlyWatts)


查看完整回答
反對 回復 2022-10-27
?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

在后端模塊中,代碼為:


import { fetch } from 'wix-fetch'


export function getCryptoCurrencyInfo() {

  const url = 'https://dweet.io/get/dweets/for/shyam__5'

  console.log(url)


  return fetch(url, { method: 'get' }).then(response => response.json())

}

為了讓它工作,網站頁面(前端)這樣說:


// For full API documentation, including code examples, visit https://wix.to/94BuAAs


import { getCryptoCurrencyInfo } from 'backend/serviceModule'

import { fetch } from 'wix-fetch'


$w.onReady(function() {

  //TODO: write your page related code here...


  getCryptoCurrencyInfo().then(currencyInfo => {

    const data = currencyInfo

    console.log(data.with[1].content.yearlyWatts)

    console.log(data.with[2].content.monthlyWatts)

    console.log(data.with[3].content.currentDailyCarbonSaved)

    console.log(data.with[4].content.currentDailyWatts)

  })

})


查看完整回答
反對 回復 2022-10-27
?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

考慮到global_obj你的json_object,你可以這樣做

global_obj.with.find(element => element.thing==="shyam__5");


查看完整回答
反對 回復 2022-10-27
  • 3 回答
  • 0 關注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號