Editing JSON Array contents in Ruby

前端 未结 2 359
长情又很酷
长情又很酷 2021-01-24 07:54

My JSON array is structured like this:

{\"data\":[{\"Chris\":[{\"long\":10,\"lat\":19}]},{\"Scott\":[{\"long\":9,\"lat\":18}]}]}

In the ruby pr

2条回答
  •  攒了一身酷
    2021-01-24 08:41

    username = 'Chris'
    sections.each do |user_coords|
      user_coords.each do |user, coords|
        if user == username then
          coords.each do |lat_long|
            lat_long['lat']  = 123 # Your value here...
            lat_long['long'] = 456 # Your value here...
          end
        end
      end
    end
    sections.to_json # => '[{"Chris":[{"long":456,"lat":123}]}...]'
    

提交回复
热议问题