Advertisement
Guest User

ReadJSON

a guest
Oct 17th, 2011
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. void Update() {
  2.  
  3. JSONObject j = new JSONObject("file://" + Application.dataPath + "/Resources/sample.json");
  4. accessData(j);
  5.  
  6. }
  7.  
  8. void accessData(JSONObject obj){
  9. switch(obj.type){
  10. case JSONObject.Type.OBJECT:
  11. for(int i = 0; i < obj.list.Count; i++){
  12. string key = (string)obj.keys[i];
  13. JSONObject j = (JSONObject)obj.list[i];
  14. Debug.Log(key);
  15. accessData(j);
  16. }
  17. break;
  18. case JSONObject.Type.ARRAY:
  19. foreach(JSONObject j in obj.list){
  20. accessData(j);
  21. }
  22. break;
  23. case JSONObject.Type.STRING:
  24. Debug.Log(obj.str);
  25. break;
  26. case JSONObject.Type.NUMBER:
  27. Debug.Log(obj.n);
  28. break;
  29. case JSONObject.Type.BOOL:
  30. Debug.Log(obj.b);
  31. break;
  32. case JSONObject.Type.NULL:
  33. Debug.Log("NULL");
  34. break;
  35.  
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement