ruby - Issue on parsing string at JSON.parse -


in controller side getting params like

"{\"violation_date\":\"sdfsdf\",\"violation_time\":\"\"},{\"violation_date\":\"sdfdsf\",\"violation_time\":\"sdfsdf\"},{\"violation_date\":\"1233\",\"violation_ time\":\"\"},{\"violation_date\":\"test\",\"violation_time\":\"time\"}" 

class of string. trying parse this. through

json.parse(params_gotton) 

got

 json::parsererror (757: unexpected token @ ',{"violation_date":"sdfdsf","violation_time":"sdfsdf"},{"violation_date":"1233","violation_time":""},{"violation_d te":"test","violation_time":"time"}'): 

what doing wrong here. suggestions?

it's not valid json, work (use []):

require 'json' jsn = '[{"violation_date":"sdfsdf","violation_time":""}, {"violation_date":"sdfdsf","violation_time":"sdfsdf"}, {"violation_date":"1233","violation_time":""}, {"violation_date":"test","violation_time":"time"}]'  json.parse(jsn) # => [{"violation_date"=>"sdfsdf", "violation_time"=>""}, {"violation_date"=>"sdfdsf", "violation_time"=>"sdfsdf"}, {"violation_date"=>"1233", "violation_time"=>""}, {"violation_date"=>"test", "violation_time"=>"time"}] 

to verify json string use: http://www.jslint.com/. , basic json structure: http://json.org/

updated

in case try this:

json.parse('[' + params_gotton + ']') 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -