tjconv_fromjson.bmx 610 B

12345678910111213141516171819202122232425262728
  1. SuperStrict
  2. Framework brl.standardio
  3. Import Text.jconv
  4. ' a serialized object as json
  5. Local txt:String = "{~qposition~q:{~qx~q:100,~qy~q:50},~qspeed~q:{~qx~q:50,~qy~q:75}}"
  6. ' create jconv instance
  7. Local jconv:TJConv = New TJConvBuilder.Build()
  8. ' deserialize into a TPlayer object
  9. Local player:TPlayer = TPlayer(jconv.FromJson(txt, "TPlayer"))
  10. If player Then
  11. Print "Position = " + player.position.x + ", " + player.position.y
  12. Print "Speed = " + player.speed.x + ", " + player.speed.y
  13. End If
  14. Type TPlayer
  15. Field position:TVec2
  16. Field speed:TVec2
  17. End Type
  18. Type TVec2
  19. Field x:Int
  20. Field y:Int
  21. End Type