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
  1. Home
  2. Web Development
  3. Error when trying to add array element to hash - RUBY

Error when trying to add array element to hash - RUBY

Scheduled Pinned Locked Moved Web Development
jsonhelprubydatabasedata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13569823
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

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