当前位置:网站首页>JSON string conversion in unity
JSON string conversion in unity
2022-07-04 03:21:00 【Live in another place】
Unity Access the network API When , Often need to be right Json String conversion .Unity Bring one with you Json Converted classes JsonUtility. But this class is not powerful enough , Only simple conversion .
Actually Unity2020 Have already put Newtonsoft.Json Built in .
This function is better than JsonUtility A lot of powerful . When you use it , Add a reference .
For example, the following Json character string
use JsonUtility Conversion cannot backResult Convert it out , use Newtonsoft.Json You can convert the correct result .
For example, the following code :
using UnityEngine;
using Newtonsoft.Json;
public class JsonToObj : MonoBehaviour
{
string jsonString = "{\"code\":200,\"msg\":\" success \",\"backResult\":{\"sessionID\":\"205ec794-767f-4fd7-ab6e-7d087989e990\",\"rtmpAddr\":\"rtmp://122.1.11.30:20002/live/205ec794-767f-4fd7-ab6e-7d087989e990?user=scth\",\"flvAddr\":\"http://122.1.11.30:20007/flv?port=20002&app=live&stream=205ec794-767f-4fd7-ab6e-7d087989e990&user=scth\",\"hlsAddr\":\"http://122.1.11.30:20007/hls/205ec794-767f-4fd7-ab6e-7d087989e990.m3u8?user=scth\",\"code\":200,\"info\":\" Push successful \"}}";
void Start()
{
StreamingGet sg;
sg = JsonUtility.FromJson<StreamingGet>(jsonString);
Debug.Log("JsonUtility.FromJson");
Debug.Log("code:" + sg.code);
Debug.Log("backResult:" + sg.backResult);
//Debug.Log("backResult.seesion:" + sg.backResult.sessionID);
sg = JsonConvert.DeserializeObject<StreamingGet>(jsonString);
Debug.Log("JsonConvert.DeserializeObject");
Debug.Log("code:" + sg.code);
Debug.Log("backResult:" + sg.backResult);
Debug.Log("backResult.seesion:" + sg.backResult.sessionID);
}
}
The effect after running
Source link :https://gitee.com/BackFlowLake/UnityAndJson
边栏推荐
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
- Teach you how to optimize SQL
- The "two-way link" of pushing messages helps app quickly realize two-way communication capability
- 機器學習基礎:用 Lasso 做特征選擇
- Johnson–Lindenstrauss Lemma
- Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
- Experience summary of the 12th Blue Bridge Cup (written for the first time)
- Lichuang EDA learning notes 14: PCB board canvas settings
- New year's first race, submit bug reward more!
猜你喜欢
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Crawler practice website image batch download
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
Webhook triggers Jenkins for sonar detection
MySQL is dirty
Monitoring - Prometheus introduction
Setting methods, usage methods and common usage scenarios of environment variables in postman
Node solves cross domain problems
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
随机推荐
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Lichuang EDA learning notes 14: PCB board canvas settings
Formulaire day05
Day05 錶格
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
Want to do something in production? Then try these redis commands
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
Rhcsa day 2
[untitled]
Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
Handler source code analysis
長文綜述:大腦中的熵、自由能、對稱性和動力學
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
Database concept and installation
CSP drawing
Kiss number + close contact problem
Site favorites
Solve the problems encountered by the laravel framework using mongodb
Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram