Skip to main content
edited the Json format
Source Link
user1509674
  • 807
  • 1
  • 20
  • 45

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
            "option" : {
               "option1":"1" ,
               "option2": "2"
                }
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

I have used this code.Iam getting the output

using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()
{
    Data data = new Data();
    data.id = 1;
    data.payload = new Payload() { text = "wwwwwww", image = "hello" };
    //json = JsonMapper.ToJson(data) ;
    string json = JsonUtility.ToJson(data);
    P (json);
    //      P(json + "\t\n");

 }

// Use this for initialization
void P(string aText)
{
    print (aText +"\n");
}

}

  [System.Serializable]
 public class Payload
  {
    public string text;
       public string image;
 }

     [System.Serializable]
    public class Data
  {
        public int id;
        public Payload payload;
  }

The output is getting displayed in a single line

{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}

But I need the output to be printed as the Json format.I tried giving space.

Can anybody please help me out?

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

I have used this code.Iam getting the output

using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()
{
    Data data = new Data();
    data.id = 1;
    data.payload = new Payload() { text = "wwwwwww", image = "hello" };
    //json = JsonMapper.ToJson(data) ;
    string json = JsonUtility.ToJson(data);
    P (json);
    //      P(json + "\t\n");

 }

// Use this for initialization
void P(string aText)
{
    print (aText +"\n");
}

}

  [System.Serializable]
 public class Payload
  {
    public string text;
       public string image;
 }

     [System.Serializable]
    public class Data
  {
        public int id;
        public Payload payload;
  }

The output is getting displayed in a single line

{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}

But I need the output to be printed as the Json format.I tried giving space.

Can anybody please help me out?

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
            "option" : {
               "option1":"1" ,
               "option2": "2"
                }
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

I have used this code.Iam getting the output

using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()
{
    Data data = new Data();
    data.id = 1;
    data.payload = new Payload() { text = "wwwwwww", image = "hello" };
    //json = JsonMapper.ToJson(data) ;
    string json = JsonUtility.ToJson(data);
    P (json);
    //      P(json + "\t\n");

 }

// Use this for initialization
void P(string aText)
{
    print (aText +"\n");
}

}

  [System.Serializable]
 public class Payload
  {
    public string text;
       public string image;
 }

     [System.Serializable]
    public class Data
  {
        public int id;
        public Payload payload;
  }

The output is getting displayed in a single line

{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}

But I need the output to be printed as the Json format.I tried giving space.

Can anybody please help me out?

added code
Source Link
user1509674
  • 807
  • 1
  • 20
  • 45

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

I have used this code.Iam getting the output

using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()
{
    Data data = new Data();
    data.id = 1;
    data.payload = new Payload() { text = "wwwwwww", image = "hello" };
    //json = JsonMapper.ToJson(data) ;
    string json = JsonUtility.ToJson(data);
    P (json);
    //      P(json + "\t\n");

 }

// Use this for initialization
void P(string aText)
{
    print (aText +"\n");
}

}

  [System.Serializable]
 public class Payload
  {
    public string text;
       public string image;
 }

     [System.Serializable]
    public class Data
  {
        public int id;
        public Payload payload;
  }

The output is getting displayed in a single line

{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}

But I need the output to be printed as the Json format.I tried giving space.

Can anybody please help me out?

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

Can anybody please help me out?

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

I have used this code.Iam getting the output

using UnityEngine;
using System.Collections;
using LitJson;
using System.IO;
public class JsonScript : MonoBehaviour {
JsonData json;
void Start()
{
    Data data = new Data();
    data.id = 1;
    data.payload = new Payload() { text = "wwwwwww", image = "hello" };
    //json = JsonMapper.ToJson(data) ;
    string json = JsonUtility.ToJson(data);
    P (json);
    //      P(json + "\t\n");

 }

// Use this for initialization
void P(string aText)
{
    print (aText +"\n");
}

}

  [System.Serializable]
 public class Payload
  {
    public string text;
       public string image;
 }

     [System.Serializable]
    public class Data
  {
        public int id;
        public Payload payload;
  }

The output is getting displayed in a single line

{"id":1,"payload":{"text":"wwwwwww","image":"hello"}}

But I need the output to be printed as the Json format.I tried giving space.

Can anybody please help me out?

communicate unity Communicate Unity application via a series of Json

I am working on communicating unity application via a series of Json.Since Since I am new to Json JSON,I doesnt I don't have any idea how that work with unityWnity.

Here is my JsonJSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in unityUnity scene.I I have hardcoded the image and text data.When When I click on the button the data should get converted into Json and should send jsonJSON data to the server and print a data log message.

Can anybody please help me out.?

communicate unity application via a series of Json

I am working on communicating unity application via a series of Json.Since I am new to Json ,I doesnt have any idea how that work with unity.

Here is my Json structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in unity scene.I have hardcoded the image and text data.When I click on the button the data should get converted into Json and should send json data to the server and print a data log message.

Can anybody please help me out.

Communicate Unity application via a series of Json

I am working on communicating unity application via a series of Json. Since I am new to JSON, I don't have any idea how that work with Wnity.

Here is my JSON structure

{
    "id": “id",
    "payload": {
            “image”: "Image Url”
            "text":"text message"
    }

}

Now I have created a button in Unity scene. I have hardcoded the image and text data. When I click on the button the data should get converted into Json and should send JSON data to the server and print a data log message.

Can anybody please help me out?

Source Link
user1509674
  • 807
  • 1
  • 20
  • 45
Loading