- Home /
Print JSON to screen as a block of text in unity during runtime
I am using unity3d and I have a JSON object. I am able to access each member using ob.name and so on but I am looking to get this deserialized block to be printed on my screen during run time.Similar to a search result , so I get the JSON as a result of search and I want to display it on my screen.I get errors that I cannot print the object because I used (ob.name)toString(); I am not sure how to display this during run time on the screen. ObjR rs = JsonUtility.FromJson(jsonString); //so now I want to print to screen each element of rs.How do I do that during runtime. I am able to see on Debug.Log , I just need to dynamically print them on screen.Please note , the size or number of results is on runtime and will vary.Any help is appreciated.Thanks
Answer by unit_nick · Sep 07, 2017 at 12:56 PM
// possibly much better ways of ding this, but this will work
using UnityEngine;
public class ScreenDisplay : MonoBehaviour
{
public string text = "the quick brown fox jumps over the lazy dog";
private void OnGUI()
{
GUIStyle style = new GUIStyle();
Rect rect = new Rect(0, 0, Screen.width, Screen.height);
style.alignment = TextAnchor.MiddleCenter;
style.fontSize = 12;
style.normal.textColor = new Color (0.0f, 0.0f, 0.5f, 1.0f);
GUI.Label(rect, text, style);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612134343im_/https://answers.unity.com/themes/thub/images/avi.jpg)