According to the json standard a - in front of a number is allowed while a + isn't.
The example should have looked like this
Code: Select all
{"key":-4.44}
Code: Select all
{"key":-4.44}
Code: Select all
declare function LoadFileAsString(byval filename as string) as string
#include once "fbJson.bi"
dim as string jsontext = LoadFileAsString("engines.json")
'print(jsontext)
dim as jsonItem item = jsonItem(jsontext)
print(item.Datatype = malformed)
function LoadFileAsString(byval filename as string) as string
dim s as string
if open(filename for input access read as #1) = 0 then
close #1
if open(filename for binary access read as #1) = 0 then
s = space(lof(1))
get #1,, s
close #1
else
print "Unable to open '" & filename & "'"
end if
else
print "File not found '" & filename & "'"
end if
return s
end function
I don't see where the problem is.-1
Code: Select all
fbJSON Error: Could not de-escape 'c:\\chess\\fruit' encountered at position 3 on line 7.
I don't know why, I met exactly the same problem with Kristopher Windsor JSON parser. I tried to fix the code by myself without success. :)StringEpsilon wrote:The culprit is the "\\". I think I straight up forgot to implement that case.
Edit: Sorry, I had forgotten to trim the string.fbJSON Error: Array was not properly closed. Expected ']' at position 3 on line 16, found '' instead.
Code: Select all
declare function LoadFileAsString(byval filename as string) as string
#define fbJSON_Debug
#include once "fbJson.bi"
dim as string jsontext = LoadFileAsString("engines.json")
jsontext = Trim(jsontext, any Chr(13, 10))
dim as jsonItem item = jsonItem(jsontext)
Assert(item.Datatype <> malformed)
Assert(item.Datatype = jsonArray)
Assert(item[0].DataType = jsonObject)
dim as jsonItem item1
for i as integer = 0 to item.Count - 1
item1 = jsonItem(item[i])
Assert(item1["name"].DataType = jsonString)
? item1["name"].Value
next i
function LoadFileAsString(byval filename as string) as string
dim s as string
if open(filename for input access read as #1) = 0 then
close #1
if open(filename for binary access read as #1) = 0 then
s = space(lof(1))
get #1,, s
close #1
else
print "Unable to open '" & filename & "'"
end if
else
print "File not found '" & filename & "'"
end if
return s
end function
Fruit
Pharaon
Code: Select all
dim as jsonItem item1
for i as integer = 0 to item.Count - 1
item1 = jsonItem(item[i])
Assert(item1["name"].DataType = jsonString)
? item1["name"].Value
? item1["workingDirectory"].Value
next i
Fruit
\\engines\fruit\-
Pharaon
\\engines\pharaon\-
Thank you. This will come in very handy, and seems that you already have a tester ;)StringEpsilon wrote:Bump: Been a while, but I just got in the mood again and updated fbJSON today.
Today I did another test. I hope you will like it. :)paul doe wrote:Thank you. This will come in very handy, and seems that you already have a tester ;)StringEpsilon wrote:Bump: Been a while, but I just got in the mood again and updated fbJSON today.
Code: Select all
' 0.17:
dim as jsonItem item
item.AppendChild("17\u2665")
print item[0] ' prints: "17", datatype is jsonNumber
item.AppendChild("\u2665")
' Error, item now malformed.
' 0.18:
dim as jsonItem item
item.AppendChild("17\u2665")
print item[0] ' prints: "17♥", datatype is jsonString
item.AppendChild("\u2665")
' Item[1] now "♥"
Code: Select all
' 17:
? jsonItem("17e1e1").value ' "170, datatype jsonNumber
? jsonItem("17.1.1").value ' "17.1, datatype jsonNumber