drvonr6573 2016-02-17 21:06
浏览 14

如何解析来自AWS Go API的响应

I am using the following sample program:

func getEnv(appName string, env string) {
    svc := elasticbeanstalk.New(session.New(), &aws.Config{Region: aws.String("us-east-1")})

    params := &elasticbeanstalk.DescribeConfigurationSettingsInput{
        ApplicationName: aws.String(appName), // Required
        EnvironmentName: aws.String(env),
    }
    resp, err := svc.DescribeConfigurationSettings(params)

    if err != nil {
        fmt.Println(err.Error())
        return
    }
    v := resp.ConfigurationSettings
    fmt.Printf("%s", v)
}

It's printing out the following response; this looks like a valid json except for the missing quote makes. ex: ApplicationName and not "ApplicationName".

How do I parse this? or get a valid json from AWS?

ConfigurationSettings: [{
          ApplicationName: "myApp",
          DateCreated: 2016-01-12 00:10:10 +0000 UTC,
          DateUpdated: 2016-01-12 00:10:10 +0000 UTC,
          DeploymentStatus: "deployed",
          Description: "Environment created from the EB CLI using \"eb create\"",
          EnvironmentName: "stag-myApp-app-s1",
          OptionSettings: [
            ...
  • 写回答

1条回答 默认 最新

  • dsoxcj7276 2016-02-18 05:15
    关注

    resp.ConfigurationSettings is not in JSON format any more, the aws-sdk-go package handled that for you. When you do,

    v := resp.ConfigurationSettings
    

    v contains an instance []*ConfigurationSettingsDescription that was parsed from the JSON response, and you don't have to parse it yourself. What you are seeing when you print it out is the Go struct representation. You can just go ahead and use it:

    if len(v) > 0 {
        log.Println(v[0].ApplicationName)
    }
    

    This should print out myApp

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序