JSON::ParseError
swistaczek opened this issue · 2 comments
swistaczek commented
Hello,
I pasted my code and whole error msg at http://pastie.org/2302755
JSON::ParserError in Admin/users#index
I dont know what is going on, I am doing right the same like in readme.
Thanks in advantage for help.
chdorner commented
I have the exact same problem, the code shown in README actually produces wrong JSON.
arr = [1,2,3,4,5,6,7,8,9,0]
json = JSONBuilder::Generator.new
json.posts do
json.array! arr do
arr.each do |a|
json.array_item! do
json.id a
end
end
end
end
puts json.compile!
The above code produces:
[{"posts":{"id":1},{"id": 2},{"id": 3},{"id": 4},{"id": 5},{"id": 6},{"id": 7},{"id": 8},{"id": 9},{"id": 0}}]
But it should produce:
{"posts":[{"id":1},{"id": 2},{"id": 3},{"id": 4},{"id": 5},{"id": 6},{"id": 7},{"id": 8},{"id": 9},{"id": 0}]}
dewski commented
I have fixed this with json_builder 3.0 which I am releasing shortly, which has a new and easier to use API. So to do that with the new API, it will be:
posts [1,2,3,4,5,6,7,8,9,0] do |i|
id i
end