Unexpected token in JSON at position 0
-1
-1
Anyone knows where is the mistake?
Code: Select all
Debug Input$
Enumeration
#file_read
#json_result
EndEnumeration
Structure Location
x.l
y.l
EndStructure
Global NewList Locations.Location()
For i = 0 To 10
AddElement(Locations())
Locations()\x = Random(100)
Locations()\y = Random(100)
Next
Procedure fileReadCall(Status, Filename$, File, Size)
If Status = #PB_Status_Loaded
Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
Debug "Reading.."
Input$ = ReadString(#file_read,#PB_UTF8 | #PB_File_IgnoreEOL)
Debug Input$
If ParseJSON(#json_result,Input$)
ClearList(Locations())
ExtractJSONList(JSONValue(#json_result),Locations())
ForEach Locations()
Debug Str(Locations()\x) + ", " + Str(Locations()\y)
Next
Else
Debug "json read error"
Debug JSONErrorMessage()
Debug JSONErrorLine()
Debug JSONErrorPosition()
EndIf
EndIf
EndProcedure
Procedure fileImporReaded()
If NextSelectedFile()
ReadFile(#file_read, SelectedFileID(), @fileReadCall(), #PB_LocalFile | #PB_UTF8)
EndIf
EndProcedure
fileson = CreateJSON(#PB_Any)
InsertJSONList(JSONValue(fileson),Locations())
ExportJSON(fileson,"demo.json")
Procedure ChooseFileEvent()
OpenFileRequester(".json",@fileImporReaded(),#PB_Requester_MultiSelection)
EndProcedure
OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a text file...")
BindGadgetEvent(0, @ChooseFileEvent())