Unity 3D JSON nested use and multiple type matching

Source: Internet
Author: User
Tags tojson

We control the end to send a lot of commands to the terminal equipment, which have speed, direction, open door, switch lights .... Method of thousands of species, I only take a scoop. I'm too young to know what other people are writing about. I like to put the regular things together to write! For my obsessive-compulsive disorder!

  

usingUnityengine;usingSystem.Collections;usingSystem; Public classJson:monobehaviour { PublicJsontype msg =NewJsontype ();  PublicSpeed speed =NewSpeed (); [Serializable] Public classJsontype { Public inttype;  Public stringstr; } [Serializable] Public classSpeed { Public intID;  Public intSpeed ; } [Serializable] Public classDirection { Public intID;  Public intdirection; }    voidStart () {Msg.type=1; Speed.id=1; Speed.speed= -; Msg.str=Jsonutility.tojson (speed); stringMessage =Jsonutility.tojson (msg); intType = jsonutility.fromjson<jsontype>(message). Type; stringstr = jsonutility.fromjson<jsontype>(message). Str; Print ("message:"+message); Print ("Type:"+type); Print ("Str:"+str); Switch(type) { Case 1: Print ("Speed :"+jsonutility.fromjson<speed>(str). Speed);  Break; default:                 Break; }           }}

Unity 3D JSON nested use and multiple type matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.