当前位置:网站首页>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
边栏推荐
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- Tsinghua University product: penalty gradient norm improves generalization of deep learning model
- There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
- POSTECH | option compatible reward reverse reinforcement learning
- How to use websocket to realize simple chat function in C #
- Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
- AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
- MySQL backup notes
猜你喜欢

Li Chuang EDA learning notes IX: layers

1day vulnerability pushback skills practice (3)

Monitoring - Prometheus introduction

I stepped on a foundation pit today

Jenkins continuous integration environment construction V (Jenkins common construction triggers)

96% of the collected traffic is prevented by bubble mart of cloud hosting

Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.

false sharing

Johnson–Lindenstrauss Lemma

Redis notes (I) Linux installation process of redis
随机推荐
Rhcsa day 3
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
MySQL backup notes
CSP drawing
The "two-way link" of pushing messages helps app quickly realize two-way communication capability
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
(practice C language every day) pointer sorting problem
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Latex tips slash \backslash
Slurm view node configuration information
How much does it cost to open a futures account in China? Where is it safe to open an account at present?
Jenkins configures IP address access
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Is online futures account opening safe and reliable? Which domestic futures company is better?
Handler source code analysis
2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an