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