草庐IT

arrays - 如何解析字段名称中具有随机哈希值的golang json数组

coder 2024-07-12 原文

<分区>

我正在尝试在 golang 代码中从 API 解析 JSON。 与 true 选项参数一起传递时,它提供不同的附加信息,而 false 则提供不同的输出。 我在以下 golang 播放链接中介绍了这一点: https://play.golang.org/p/-JffO4AS01N

我需要解析变量mtJson的值。

使用 Json to Go ( https://mholt.github.io/json-to-go/ ) 转换以获得为此创建结构类型的帮助。但它为 json 示例提供了以下结构类型:

{
"result": {
"99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738": {
"size": 845,
"fee": 0.000144,
"time": 1547444481,
"height": 1183405,
"startingpriority": 89509.20245398773,
"currentpriority": 89509.20245398773,
"depends": []
},
"73f582cf419f8b1cd6a87f81e0e9a4e783add27c2be083361e8eb4a3bac0134e": {
"size": 1635,
"fee": 0.000312,
"time": 1547444435,
"height": 1183405,
"startingpriority": 341863.3540372671,
"currentpriority": 341863.3540372671,
"depends": []
}
},
"error": null,
"id": "curltest"
}
type AutoGenerated struct {
    Result struct {
        Nine9C4D91Acc2486955C98015Fbbdf06239B983C9D93D5069C39D040702Af88738 struct {
            Size             int           `json:"size"`
            Fee              float64       `json:"fee"`
            Time             int           `json:"time"`
            Height           int           `json:"height"`
            Startingpriority float64       `json:"startingpriority"`
            Currentpriority  float64       `json:"currentpriority"`
            Depends          []interface{} `json:"depends"`
        } `json:"99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738"`
        Seven3F582Cf419F8B1Cd6A87F81E0E9A4E783Add27C2Be083361E8Eb4A3Bac0134E struct {
            Size             int           `json:"size"`
            Fee              float64       `json:"fee"`
            Time             int           `json:"time"`
            Height           int           `json:"height"`
            Startingpriority float64       `json:"startingpriority"`
            Currentpriority  float64       `json:"currentpriority"`
            Depends          []interface{} `json:"depends"`
        } `json:"73f582cf419f8b1cd6a87f81e0e9a4e783add27c2be083361e8eb4a3bac0134e"`
    } `json:"result"`
    Error interface{} `json:"error"`
    ID    string      `json:"id"`
}

这似乎不对。

字符串哈希键的值总是不同的,不确定,所以不能像在结构中那样设置。

我对如何解析 JSON 以便最终获得这样的值感到困惑:


fmt.Println(mt.Result.("99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738").Size)

fmt.Println(mt.Result.("99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738").Fee)

请帮忙

我在以下 golang 播放链接中介绍了这一点: https://play.golang.org/p/-JffO4AS01N

我在以下 golang 播放链接中介绍了这一点: https://play.golang.org/p/-JffO4AS01N

预期: fmt.Println(mt.Result.("99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738").大小) 845

fmt.Println(mt.Result.("99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738").Fee) 0.000144

实际结果:{{0 0 0 0 0 0 []}}

有关arrays - 如何解析字段名称中具有随机哈希值的golang json数组的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. Ruby 解析字符串 - 2

    我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?

  4. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  5. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  6. ruby - 在 Ruby 中实现 `call_user_func_array` - 2

    我怎样才能完成http://php.net/manual/en/function.call-user-func-array.php在ruby中?所以我可以这样做:classAppdeffoo(a,b)putsa+benddefbarargs=[1,2]App.send(:foo,args)#doesn'tworkApp.send(:foo,args[0],args[1])#doeswork,butdoesnotscaleendend 最佳答案 尝试分解数组App.send(:foo,*args)

  7. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  8. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  9. ruby-on-rails - 在 Ruby 中循环遍历多个数组 - 2

    我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代

  10. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

随机推荐