ios - Rails "as_json" method returning invalid json? -
i trying have ios application read json generated rails server. now, having text file, eventual goal retrieved via route.
the ios application throwing errors trying read (which generated as_json):
{"created_at"=>fri, 16 aug 2013 13:21:07 utc +00:00, "gender"=>"m", "id"=>1, "location_id"=>1, "max_hit_points"=>nil, "my_name"=>"jim bob", "npc_type_id"=>nil, "universe_id"=>1, "updated_at"=>fri, 16 aug 2013 13:21:07 utc +00:00}
when give json validator (http://jsonformatter.curiousconcept.com)
i several errors everything, how has "=>" rather colon.
am doing weird? why rails seem not generate valid json? there somehow multiple types of valid json (arrows vs colons?) how can make generate json ios app (or validator) likes?
as_json
used prepare hash suitable json rendering. (see doc)
you need call to_json
real json string.
for example :
your_object.as_json.to_json
more info on difference , implications can found here