• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to make a JSON string in unity?

Resolved: How to make a JSON string in unity?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I need to send some data as JSON to a server, and using JSONUtility didn’t really work as well as I thought, is there a simple and more readable way to write this?
The JSON should look like this if the URL is provided:
And like this, if no URL is provided:

Answer:

This can be solved by using the JsonUtility class provided by UnityEngine namespace.
First, Create a data class to extract as JSON.
Second, Fill in the values in a method that generates JSON data. (It is filled in differently depending on the url or not.) Then, extract it to JSON using JsonUtility.ToJson().
The following is the output result by inputting a random value.
When there is a value in urlInput.text
When urlInput.text is empty
I referred to the information you provided when writing the code, but I modified the part in Spanish.
Hope your problem is solved ๐Ÿ™‚

If you have better answer, please add a comment about this, thank you!

c# json unity3d
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Resolved: Regex: Curly braces in reverse? Match X characters before a string?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.