Tag: json

使用Ruby迭代JSON并获取数组中的键值

我在使用这个JSON时遇到了一些麻烦: { “ENAX-BRANCHESM-10” : { “repo”:”test-ASO”, “PATH”:”/tmp/pruebaAlvaro”, “ARTIFACTS”:”example1.jar,another_one.jar,and_another.jar”, “uri”:”http://server:8081/artifactory/test-ASO”, “created”:”A705663″ }, “QZQP-QZQPMAN-16” : { “repo”: “test-ASO”, “PATH”: “/tmp/pruebaAlvaro2”, “ARTIFACTS”: “test543.jar,thisisa.jar,yesanother.jar”, “uri”: “http://server:8081/artifactory/test-ASO”, “created”: “A705663” } } 我正在尝试遍历列表以获取每个列表的PATH和ARTIFACTS值,在示例中有两个列表,但实际上有几十个。 目的是了解将哪个工件部署到其自己的路径。 例如: /tmp/pruebaAlvaro example1.jar /tmp/pruebaAlvaro another_one.jar /tmp/pruebaAlvaro and_another.jar /tmp/pruebaAlvaro2 test543.jar /tmp/pruebaAlvaro2 thisisa.jar /tmp/pruebaAlvaro2 yesanother.jar 在我深入搜索之后,我仍然无法得到解决方案。

在rails中将JSON字符串转换为JSON数组?

我在rails中有一个JSON字符串,如下所示: [{“content”:”1D”,”createdTime”:”09-06-2011 00:59″},{“content”:”2D”,”createdtime”:”09-06-2011 08:00″}] 哪些是具有属性内容和创建时间的类内容的对象。 我想将此JSON字符串转换为其各自的JSON对象数组,以便我可以运行循环并将JSON解码为其在rails中的对象。 我怎样才能做到这一点?

在Ruby中编辑JSON数组内容

我的JSON数组的结构如下: {“data”:[{“Chris”:[{“long”:10,”lat”:19}]},{“Scott”:[{“long”:9,”lat”:18}]}]} 在ruby程序中,我希望能够编辑名称的lat和long值。 但我不太清楚该怎么做。 sections.each do |user_coords| user_coords.each do |user, coords| if user == Usrname then #Change lat and long value for Usrname end end end 如何才能做到这一点?

如何访问JSON数组数据?

我有以下数组: [ { “attributes”: { “id”: “usdeur”, “code”: 4 }, “name”: “USD/EUR” }, { “attributes”: { “id”: “eurgbp”, “code”: 5 }, “name”: “EUR/GBP” } ] 如何将两个ID作为输出进行进一步处理? 我尝试了很多但没有成功。 我的问题是我总是只得到一个id作为输出: Market.all.select.each do |market| present market.id end 要么: Market.all.each{|attributes| present attributes[:id]} 这让我只有“eurgbp”,因为我需要两个ID。

Ruby on Rails不兼容的库

我刚刚开始看看rails上的ruby并且无法运行服务器。 我正在运行ruby 2.3.0和rails 4.2.5并且在我有一个新的铁路项目之后我尝试运行bin/rails server但是得到以下错误: Warning: Running `gem pristine –all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle –path) will improve the startup performance of Spring. /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:13:in `require’: incompatible library version – /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext/parser.bundle (fatal) from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:13:in `’ from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:12:in `’ from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:9:in `’ from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json.rb:58:in `require’ from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json.rb:58:in […]

Rails从JSON数组中选择

我有一个从Foursquare返回的JSON数组; 我们称之为@venues 。 我希望能够通过下拉框“选择”一个场地,我希望它能成为表格的一部分。 这意味着我希望能够按名称选择一个特定的场地(即在这种情况下,酒店犹他州沙龙),并将其id保存到模型中。 为了澄清,我只会保存我选择的场地,而不是全部。 通过研究,我发现自己在select , collection_select和select_tag之间感到困惑。 请记住,这是JSON直接来自JSON.parse方法,而不是数据库模型。 如何在表单中创建此下拉列表? 为了澄清, @venues看起来像这样: [ { “beenHere”:8, “venue”:{ “id”:”3fd66200f964a52023f11ee3″, “name”:”Hotel Utah Saloon”, “contact”:{ “phone”:”4155466300″, “formattedPhone”:”(415) 546-6300″, “twitter”:”hotelutah” }, “location”:{ “address”:”500 4th St”, “crossStreet”:”Corner of Bryant”, “lat”:37.77947007181946, “lng”:-122.39816943501836, “postalCode”:”94107″, “city”:”San Francisco”, “state”:”CA”, “country”:”United States”, “cc”:”US” }, “categories”:[ { “id”:”4bf58dd8d48988d1e9931735″, “name”:”Rock Club”, “pluralName”:”Rock Clubs”, “shortName”:”Rock Club”, “icon”:”https:\/\/foursquare.com\/img\/categories\/arts_entertainment\/musicvenue_rockclub.png”, “parents”:[ […]

gem install json失败,重新定义了struct timezone / timespec

我在Windows上使用带有DevKit的Ruby 1.9.3(Win 7 64位上的所有32位)。 现在我尝试安装rails,但是从bundle中获取错误。 如果我试图运行(什么捆绑抱怨) gem install json 我收到以下错误消息: D:\RubyTest>gem install json Temporarily enhancing PATH to include DevKit… Building native extensions. This could take a while… ERROR: Error installing json: ERROR: Failed to build gem native extension. D:/Ruby193/bin/ruby.exe extconf.rb creating Makefile make generating generator-i386-mingw32.def compiling generator.c In file included from d:/Ruby193/include/ruby-1.9.1/ruby/ruby.h:1381:0, from d:/Ruby193/include/ruby-1.9.1/ruby.h:32, from […]

在Sinatrapost上阅读参数

我正在研究我的第一个Sinatra应用程序,我很难从一个post请求中获取参数。 我正在使用MiniTest :: Spec,我的规格看起来像 payload = File.read(“./spec/support/fixtures/payload.json”) post “/api/v1/verify_payload”, { payload: payload }, { “CONTENT_TYPE” => “application/json” } last_response.body.must_eql payload 这是我的路线 namespace ‘/api/v1’ do post ‘/verify_payload’ do MultiJson.load(params[:payload]) end end 规范失败,因为last_response.body为空。 我在这里错过了什么吗? 我还尝试从verify_payload返回整个params ,但在这种情况下它返回一个空字符串。 更新 curl -X POST -H “Content-Type: application/json” -d ‘{“payload”:”xyz”}’ http://localhost:9292/api/v1/verify_payload 在服务器日志中不返回任何内容并且没有错误 [2014-01-06 01:16:25] INFO WEBrick::HTTPServer#start: pid=10449 port=9292 127.0.0.1 – – [06/Jan/2014 […]

无法在Windows中安装json gem

我试图在Windows上安装json gem。 我安装了DevKit。 我在下面收到以下错误。 有什么建议? 这个问题 JSON Gem无法安装(Windows) 建议安装DevKit并尝试使用json_pure。 我做了两件事。 问题是我的bundle安装试图安装json,直到安装了json才会继续。 这是一个Rails项目btw的捆绑安装。 d:\source\my_project>gem install json -v ‘1.6.3’ Temporarily enhancing PATH to include DevKit… Building native extensions. This could take a while… ERROR: Error installing json: ERROR: Failed to build gem native extension. C:/Ruby200/bin/ruby.exe extconf.rb creating Makefile make generating parser-i386-mingw32.def compiling parser.c In file included from […]

错误:安装json时出错:错误:无法构建gem本机扩展

我正在尝试安装gem json并为json获取错误。 我在跑: Windows 8.1(64位) Ruby:ruby 1.9.3p545(2014-02-24)[i386-mingw32] gem:1.8.2 D:\GIT\calabash>gem install json -v ‘1.8.3’ Building native extensions. This could take a while… The system cannot find the path specified. ERROR: Error installing json: ERROR: Failed to build gem native extension. C:/Ruby193/bin/ruby.exe extconf.rb creating Makefile Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.3 for inspection. Results logged to […]