About Monkey 2 › Forums › Monkey 2 Programming Help › JSON module getting started
This topic contains 7 replies, has 2 voices, and was last updated by 
 wiebow
 2 years, 10 months ago.
- 
		AuthorPosts
 - 
		
			
				
June 12, 2016 at 8:55 am #1066
Hi all,
Has anyone tried using the json module? And if yes, can you get me started? I’ve been trying to find example code but cannot find it, and the monkey 1 module is slightly different and examples on the monkey 1 site don’t work. Any help is appreciated!!
June 12, 2016 at 10:35 am #1068Test…
June 12, 2016 at 10:43 am #1069Thanks!
June 12, 2016 at 11:17 am #1070Ha! Just got ‘banned’ from my own site for trying to post some code! They’re fixing it now…
June 12, 2016 at 1:31 pm #1071Good luck! The site doesn’t run on Monkey 2 code now does it!?
June 12, 2016 at 2:31 pm #1074Oh! I found this page on Monkey-X with a post from you Mark about JSON and an example: http://www.monkey-x.com/Community/posts.php?topic=10447
It should be in the bananas folder!
June 12, 2016 at 9:18 pm #1081Attempt 2…
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283Method ToJson:JsonValue( rect:Recti )Return New JsonArray( New JsonValue[]( New JsonNumber( rect.min.x ),New JsonNumber( rect.min.y ),New JsonNumber( rect.max.x ),New JsonNumber( rect.max.y ) ) )EndMethod ToRecti:Recti( value:JsonValue )Local json:=value.ToArray()Return New Recti( json[0].ToNumber(),json[1].ToNumber(),json[2].ToNumber(),json[3].ToNumber() )EndMethod LoadState()Local obj:=JsonObject.Load( "bin/ted2.state.json" )If Not obj ReturnIf obj.Contains( "openDocuments" )For Local doc:=Eachin obj["openDocuments"].ToArray()OpenDocument( doc.ToString() )NextEndifIf obj.Contains( "recentFiles" )_recent.Clear()For Local path:=Eachin obj["recentFiles"].ToArray()_recent.Push( path.ToString() )NextEndUpdateRecentFiles()If obj.Contains( "windowRect" )Frame=ToRecti( obj["windowRect"] )EndifIf obj.Contains( "consoleSize" )_docker.SetViewSize( _console,obj["consoleSize"].ToNumber() )EndifIf obj.Contains( "browserSize" )_docker.SetViewSize( _browser,obj["browserSize"].ToNumber() )EndifIf obj.Contains( "helpTreeSize" )_helpView.SetViewSize( _helpView.HelpTree,obj["helpTreeSize"].ToNumber() )EndifIf obj.Contains( "lockedDocument" )Local doc:=OpenDocument( obj["lockedDocument"].ToString() )If doc LockDoc( doc )EndifEndMethod SaveState()Local obj:=New JsonObjectLocal docs:=New JsonArrayFor Local doc:=Eachin _openDocsdocs.Add( New JsonString( doc.Path ) )Nextobj["openDocuments"]=docsLocal recent:=New JsonArrayFor Local path:=Eachin _recentrecent.Add( New JsonString( path ) )Endobj["recentFiles"]=recentobj["windowRect"]=ToJson( Frame )obj["consoleSize"]=New JsonNumber( _docker.GetViewSize( _console ) )obj["browserSize"]=New JsonNumber( _docker.GetViewSize( _browser ) )obj["helpTreeSize"]=New JsonNumber( _helpView.GetViewSize( _helpView.HelpTree ) )If _lockedDoc obj["lockedDocument"]=New JsonString( _lockedDoc.Path )SaveString( obj.ToJson(),"bin/ted2.state.json" )EndJune 13, 2016 at 7:46 am #1091Thanks Mark, I’ll give this a shot later today.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.