Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
U

User 13569823

@User 13569823
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Error when trying to add array element to hash - RUBY
    U User 13569823

    Hi all, I have a small program that makes a call to a REST API and retrieves a block of JSON. I am parsing this in Ruby which then creates a hash. Because of the way the JSON is structured I am putting the hash into an array and then extracting the second element. I am then doing some string manipulation on this element to produce another array with each element containing a string that looks like the following:-

    {:from=>"2018-01-01T00:00Z", :to=>"2018-01-01T00:30Z", :intensity=>{:forecast=>154, :actual=>157, :index=>"low"}}

    I am then trying to put each of these elements back into a hash and back into an array (so I end up with an array of hashes) so I can get access to each element of the hash through their corresponding keys. However when I try to do this within the 'each do end' loop I get an error:-

    odd number of arguments for Hash

    When I take the same string and just directly add it to the hash (like indicated below) it works fine:-

    hash["Mystring"]

    Any idea what else I can try? I can post more code if that would help. Thanks D

    Web Development json help ruby database data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups