猿问

如何使用golang从解析的json数组中获取特定值?

我正在尝试使用 twitter api 从 twitter 获取直接消息。我得到了 api json 数组 respose


[{

  "id": 694476444991229955,

  "id_str": "694476444991229955",

  "text": "Got it",

  "sender": {

    "id": 1690262984,

    "id_str": "1690262984",

    "name": "Ashok Kumar T",

    "screen_name": "Ashok_kumar_T",

    "location": "Trivandrum",

    "description": "",

    "url": null

    },

    "protected": false,

    "followers_count": 68,

    "friends_count": 32,

    "listed_count": 0,

    "created_at": "Thu Aug 22 06:52:53 +0000 2013",

    "favourites_count": 5,

    "utc_offset": 19800,

    "time_zone": "Chennai",

    "geo_enabled": true,

    "verified": false,

    "statuses_count": 124,

    "lang": "en",

    "contributors_enabled": false,

    "is_translator": false,

    "is_translation_enabled": false,

    "profile_background_color": "131516",

    "profile_background_image_url": "http:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif",

    "profile_background_image_url_https": "https:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif",

    "profile_background_tile": true,

    "profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/378800000337984382\/5eded5a0c6fda4a85511aff15e5befd9_normal.jpeg",

    "profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/378800000337984382\/5eded5a0c6fda4a85511aff15e5befd9_normal.jpeg",

    "profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/1690262984\/1429709252",

    "profile_link_color": "009999",

    "profile_sidebar_border_color": "EEEEEE",

    "profile_sidebar_fill_color": "EFEFEF",

    "profile_text_color": "333333",

    "profile_use_background_image": true,

    "has_extended_profile": false,

    "default_profile": false,

    "default_profile_image": false,

    "following": true,

    "follow_request_sent": false,

    "notifications": false

  }]


Cats萌萌
浏览 203回答 1
1回答

FFIVE

如果目标是打印第二个数组元素的标识符,则使用以下代码:myId := keys[1].ID  // l changed 1, Id changed to IDfmt.Println(myId)
随时随地看视频慕课网APP

相关分类

Go
我要回答