json loading bug ?
Monkey Forums/Monkey Programming/json loading bug ?| 
 | ||
| H! I was testing a very simple thing with json but it keeps failing. atlas.json 
{~qscores~q:[[~qglfw~q,~q9800~q],[~qhmm~q,~q3400~q],[~qbenjamin~q,~q2600~q]]}
this code works 
Strict
Import mojo
Import brl.json
Function Main:Int()
	New MyApp
	Return 0
End
Class MyApp Extends App
	Method OnCreate:Int()
		SetUpdateRate(60)		
		Local str:=LoadString("atlas.json")
		
		Print str
		Try
        	Local jso:JsonObject = New JsonObject("{~qscores~q:[[~qglfw~q,~q9800~q],[~qhmm~q,~q3400~q],[~qbenjamin~q,~q2600~q]]}")
    	Catch t:JsonError
        	Print "JsonError"
    	End
		Return 0
	End
	
	
	Method OnRender:Int()
		Cls(255, 255, 255)
		Return 0
	End
	
	
	Method OnUpdate:Int()
		Return 0
	End
	Method OnLoading:Int()
		Return 0
	End
	Method OnResize:Int()
		Return 0
	End
	Method OnSuspend:Int()
		Return 0
	End
	Method OnResume:Int()
		Return 0
	End	
	Method OnClose:Int()
		Return Super.OnClose()
	End 
	Method OnBack:Int()
		Return Super.OnBack()
	End
End
this code don't work 
Strict
Import mojo
Import brl.json
Function Main:Int()
	New MyApp
	Return 0
End
Class MyApp Extends App
	Method OnCreate:Int()
		SetUpdateRate(60)		
		Local str:=LoadString("atlas.json")
		
		Print str ' <--- did have the right string (that I use in the script above)
		Try
        	Local jso:JsonObject = New JsonObject(str)
    	Catch t:JsonError
        	Print "JsonError" ' <--------
    	End
		Return 0
	End
	
	
	Method OnRender:Int()
		Cls(255, 255, 255)
		Return 0
	End
	
	
	Method OnUpdate:Int()
		Return 0
	End
	Method OnLoading:Int()
		Return 0
	End
	Method OnResize:Int()
		Return 0
	End
	Method OnSuspend:Int()
	
		Return 0
	End
	Method OnResume:Int()
		Return 0
	End	
	Method OnClose:Int()
		Return Super.OnClose()
	End 
	Method OnBack:Int()
		Return Super.OnBack()
	End
End
using ted/mac/ Glfw2 Glfw3 and html5 for quick testing. edit without the try/catch opening openal device Monkey Runtime Error : Uncaught Monkey Exception /Applications/MonkeyXPro81b/modules/brl/json.monkey<6> /Applications/MonkeyXPro81b/modules/brl/json.monkey<471> /Applications/MonkeyXPro81b/modules/brl/json.monkey<449> /Applications/MonkeyXPro81b/modules/brl/json.monkey<51> /Users/gcmartijn/Documents/game1/game1.monkey<21> /Applications/MonkeyXPro81b/modules/mojo/app.monkey<89> TRANS FAILED: Error executing './MonkeyGame', return code=65280 | 
| 
 | ||
| The string you are loading needs Quotes in the string not the escape codes for monkeyx. If you replace all the ~q with " it will load fine. Stuart | 
| 
 | ||
| Ahh, I see it now. My original code (with good json) din't work in the first place, then I did a forum search and copy past that string using this example: http://www.monkey-x.com/Community/posts.php?topic=9338&post=97317&view=all#97317 After that it only was working using string but not using a textfile, but it makes sense. Will check it later @home. last edit yes its working. |