void FunFromJson() { //1. class -> json string PackData _packData = new PackData() { code = 1, error = 2, callCount = 3 }; string _jsonStr = JsonConvert.SerializeObject(_packData); PackData _packData2 = new PackData(); for (int i = 0; i < Constant.LOOP_MAX; i++) { _packData2 = JsonConvert.DeserializeObject <PackData>(_jsonStr); } Debug.Log("\t" + _packData2.ToString()); }
void FunToJson() { //1. class -> json string PackData _packData = new PackData() { code = 1, error = 2, callCount = 3 }; //Debug.Log(_jsonStr); //string _jsonStr = JsonConvert.SerializeObject(_packData, Formatting.Indented); string _jsonStr = ""; for (int i = 0; i < Constant.LOOP_MAX; i++) { _jsonStr = JsonConvert.SerializeObject(_packData); } Debug.Log(_jsonStr); }
void Fun_ToJson() { //1. class -> json string string _json = ""; PackData _packData = new PackData() { code = 1, error = 2, callCount = 3, name = "Apple", expire = DateTime.Now, items = new string[] { "One", "Two", "Three" } }; //_jsonStr = JsonConvert.SerializeObject(_packData, Formatting.Indented); //Debug.Log(_jsonStr); for (int i = 0; i < Constant.LOOP_MAX; i++) { _json = JsonConvert.SerializeObject(_packData); } Debug.Log(_json); }
void Fun_FromJson() { string _json = @"{ 'index': 0, 'code': 1, 'error': 2, 'callCount': 3, 'name': 'Apple', 'expire': '2020-10-14T21:33:46.5538426+09:00', 'items': [ 'One', 'Two', 'Three' ] }" ; PackData _packData = null; for (int i = 0; i < Constant.LOOP_MAX; i++) { _packData = JsonConvert.DeserializeObject <PackData>(_json); } Debug.Log("\t" + _packData.ToString()); }
private void Fun_ParseJson() { string _json = @"{ 'class' : 'go.GraphLinksModel', 'linkKeyProperty' : 'stepId', 'position' : {'x':1.1, 'y':2.2, 'z':3.3}, 'nodeDataArray' : [ { 'key':11, 'category':'start', 'text':'Start', 'loc':{'x':288, 'y':109} }, { 'key':101, 'category':'message', 'text':'Message', 'items':[ {'name':'Name', 'value':'Message'}, {'name':'Type', 'value':'Step'}, {'name':'Category', 'value':'대분류'}, {'name':'Size', 'value':'120'},{'name':'Max Length', 'value':'20'} ], 'loc':{'x':288, 'y':109} } ], }" ; //string _json = @"{ // 'index': 0, // 'code': 1, // 'error': 2, // 'callCount': 3, // 'name': 'Apple', // 'expire': '2020-10-14T21:33:46.5538426+09:00', // 'items': [ // 'One', // 'Two', // 'Three' // ] // }"; PackData _packdata = new PackData(); JObject _jo = JObject.Parse(_json); for (int i = 0; i < Constant.LOOP_MAX; i++) { //Debug.Log(_jo.SelectToken("class").ToString()); //Debug.Log(_jo.SelectToken("linkKeyProperty").ToString()); //Debug.Log(_jo.SelectToken("position").ToString()); //Debug.Log(_jo.SelectToken("position").SelectToken("x").ToString()); //Debug.Log(_jo.SelectToken("nodeDataArray").ToString()); //Debug.Log(_jo.SelectToken("nodeDataArray").SelectToken("items").ToString()); JToken _jt = _jo.SelectToken("nodeDataArray"); foreach (JToken item in _jt) { var key = item.SelectToken("key").ToString(); var category = item.SelectToken("category").ToString(); var text = item.SelectToken("text").ToString(); var items = item.SelectToken("items"); if (items != null) { foreach (var token in items) { var name = String.Format("{0}", token.SelectToken("name")); var value = String.Format("{0}", token.SelectToken("value")); } } } } }