如何开发公司的网站,手机版网站快照如何做,自己主机域名网站开发,深圳福田 外贸网站建设编写Unity程序时#xff0c;面对大量需要传输或者保存的数据时#xff0c;为了避免编写重复的代码#xff0c;故采用NewtonJson插件来将定义好的结构体以及列表等转为json字符串来进行保存和传输。 具体代码如下#xff1a;
using System;
using System.IO;
using Newtons…编写Unity程序时面对大量需要传输或者保存的数据时为了避免编写重复的代码故采用NewtonJson插件来将定义好的结构体以及列表等转为json字符串来进行保存和传输。 具体代码如下
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;struct Force
{public string forceId;public string forceName;public double longitude;public double latitude;public double height;public double speed;
}
public class GetJsonOrToJson
{ public static string getJsonByStruct(){Force force new Force();force.forceId 1;force.forceName F-22;force.longitude 120.0;force.latitude 23.0;force.height 3000.0;force.speed 150.0;string forceJson JsonConvert.SerializeObject(force);return forceJson;}public static Force onControlBtnClicked(string forceJson){Force force JsonConvert.DeserializeObjectForce(forceJson);}
}将代码中的结构体换为列表即可将对应的列表输出为json结构的字符串。