Skip to content

Example error #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ print(json.encode({ 1, 2, 'fred', {first='mars',second='venus',third='earth'} })
json = require("json")
testString = [[ { "one":1 , "two":2, "primes":[2,3,5,7] } ]]
decoded = json.decode(testString)
table.foreach(decoded, print)
for key, item pairs(decoded) do
print(key, item)
end
print ("Primes are:")
table.foreach(o.primes,print)
for key, item ipairs(decoded.primes) do
print(key, item)
end
```
```
one 1
two 2
primes table: 0032B928
Primes are:
1 2
2 3
Expand Down
8 changes: 6 additions & 2 deletions examples/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ print('JSON encoded test is: ' .. jsonTest)
result = json.decode(jsonTest)

print ("The decoded table result:")
table.foreach(result,print)
for key, item in pairs(result) do
print(key, item)
end
print ("The decoded table result.three")
table.foreach(result.three, print)
for i, item in ipairs(result.three) do
print(i, item)
end
2 changes: 1 addition & 1 deletion examples/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function testJSON4Lua()
-- Test json.null management
t = { 1,2,json.null,4 }
assert( json.encode(t)=="[1,2,null,4]" )
t = {x=json.null }
t = {x=null }
r = json.encode(t)
assert( json.encode(t) == '{"x":null}' )

Expand Down
5 changes: 3 additions & 2 deletions json/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function json.decode(s, startPos)
return decode_scanString(s,startPos)
end
if string.sub(s,startPos,startPos+1)=='/*' then
return decode(s, decode_scanComment(s,startPos))
return json.decode(s, decode_scanComment(s,startPos))
end
-- Otherwise, it must be a constant
return decode_scanConstant(s,startPos)
Expand All @@ -161,6 +161,7 @@ end
-- @param startPos The starting position for the scan.
-- @return table, int The scanned array as a table, and the position of the next character to scan.
function decode_scanArray(s,startPos)
local object = {}
local array = {} -- The return value
local stringLen = string.len(s)
assert(string.sub(s,startPos,startPos)=='[','decode_scanArray called but array does not start at position ' .. startPos .. ' in string:\n'..s )
Expand Down Expand Up @@ -414,4 +415,4 @@ function isEncodable(o)
return (t=='string' or t=='boolean' or t=='number' or t=='nil' or t=='table') or (t=='function' and o==null)
end

return json
return json