当前位置: 首页 > news >正文

网站关键词密这么稀释/如何建网站详细步骤

网站关键词密这么稀释,如何建网站详细步骤,新手怎么建立自己的网站,青岛即墨区最新事件出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明 介绍 JSON是一个简单的,但功能强大的序列化数据格式。它定义了简单的类型,如布尔,数(int和float)和字符串,和几个…

出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明

介绍

JSON是一个简单的,但功能强大的序列化数据格式。它定义了简单的类型,如布尔,数(int和float)和字符串,和几个数据结构:list和dictionnary。可以在http://JSON.org了解关于JSON的更多信息。

litjson是用C #编写的,它的目的是要小,快速,易用。它使用了Mono框架。

安装LitJSON

将LitJSON编译好的dll文件通过Import New Asset的方式导入到项目中,再使用Using LitJSON即可使用JSONMapper类中的简便方法。dll的下载地址在这里.

将JSON转化为Object并可逆向转化

为了在.Net程序中使用JSON格式的数据。一个自然的方法是使用JSON文本生成一个特定的类的一个新实例;为了匹配类的格式,一般存储的JSON字符串是一个字典。

另一方面,为了将对象序列化为JSON字符串,一个简单的导出操作,听起来是个好主意。

为了这个目的,LitJSON包引入了JsonMapper类,它提供了两个用于做到  JSON转化为object 和 object转化为JSON 的主要方法。这两个方法是jsonmapper.toobject和jsonmapper.tojson。

将object转化为字符串之后,我们就可以将这个字符串很方便地在文件中读取和写入了。

一个简单的JsonMapper的例子

在下面的例子中,ToObject方法有一个泛型参数,来指定返回的某种特定的数据类型:即JsonMapper.ToObject<T>。

[csharp] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. using LitJson;  
  2. using System;  
  3.   
  4. public class Person  
  5. {  
  6.     // C# 3.0 auto-implemented properties  
  7.     public string   Name     { getset; }  
  8.     public int      Age      { getset; }  
  9.     public DateTime Birthday { getset; }  
  10. }  
  11.   
  12. public class JsonSample  
  13. {  
  14.     public static void Main()  
  15.     {  
  16.         PersonToJson();  
  17.         JsonToPerson();  
  18.     }  
  19.   
  20.     public static void PersonToJson()  
  21.     {  
  22.         Person bill = new Person();  
  23.   
  24.         bill.Name = "William Shakespeare";  
  25.         bill.Age  = 51;  
  26.         bill.Birthday = new DateTime(1564, 4, 26);  
  27.   
  28.         string json_bill = JsonMapper.ToJson(bill);  
  29.   
  30.         Console.WriteLine(json_bill);  
  31.     }  
  32.   
  33.     public static void JsonToPerson()  
  34.     {  
  35.         string json = @"  
  36.             {  
  37.                 ""Name""     : ""Thomas More"",  
  38.                 ""Age""      : 57,  
  39.                 ""Birthday"" : ""02/07/1478 00:00:00""  
  40.             }";  
  41.   
  42.         Person thomas = JsonMapper.ToObject<Person>(json);  
  43.   
  44.         Console.WriteLine("Thomas' age: {0}", thomas.Age);  
  45.     }  
  46. }  

上文的输出:

[csharp] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. {"Name":"William Shakespeare","Age":51,"Birthday":"04/26/1564 00:00:00"}  
  2. Thomas' age: 57  

使用非泛型的JsonMapper.ToObject

当不存在特定的JSON数据类时,它将返回一个JSONData实例。JSONData是一种通用型可以保存任何数据类型支持JSON,包括list和dictionary。

[csharp] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. using LitJson;  
  2. using System;  
  3.   
  4. public class JsonSample  
  5. {  
  6.     public static void Main()  
  7.     {  
  8.         string json = @"  
  9.           {  
  10.             ""album"" : {  
  11.               ""name""   : ""The Dark Side of the Moon"",  
  12.               ""artist"" : ""Pink Floyd"",  
  13.               ""year""   : 1973,  
  14.               ""tracks"" : [  
  15.                 ""Speak To Me"",  
  16.                 ""Breathe"",  
  17.                 ""On The Run""  
  18.               ]  
  19.             }  
  20.           }  
  21.         ";  
  22.   
  23.         LoadAlbumData(json);  
  24.     }  
  25.   
  26.     public static void LoadAlbumData(string json_text)  
  27.     {  
  28.         Console.WriteLine("Reading data from the following JSON string: {0}",  
  29.                           json_text);  
  30.   
  31.         JsonData data = JsonMapper.ToObject(json_text);  
  32.   
  33.         // Dictionaries are accessed like a hash-table  
  34.         Console.WriteLine("Album's name: {0}", data["album"]["name"]);  
  35.   
  36.         // Scalar elements stored in a JsonData instance can be cast to  
  37.         // their natural types  
  38.         string artist = (string) data["album"]["artist"];  
  39.         int    year   = (int) data["album"]["year"];  
  40.   
  41.         Console.WriteLine("Recorded by {0} in {1}", artist, year);  
  42.   
  43.         // Arrays are accessed like regular lists as well  
  44.         Console.WriteLine("First track: {0}", data["album"]["tracks"][0]);  
  45.     }  
  46. }  

上面例子的输出:

[csharp] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. Reading data from the following JSON string:  
  2.           {  
  3.             "album" : {  
  4.               "name"   : "The Dark Side of the Moon",  
  5.               "artist" : "Pink Floyd",  
  6.               "year"   : 1973,  
  7.               "tracks" : [  
  8.                 "Speak To Me",  
  9.                 "Breathe",  
  10.                 "On The Run"  
  11.               ]  
  12.             }  
  13.           }  
  14.   
  15. Album's name: The Dark Side of the Moon  
  16. Recorded by Pink Floyd in 1973  
  17. First track: Speak To Me  

Reader和Writer

一些人喜欢使用stream的方式处理JSON数据,对于他们, 我们提供的接口是jsonreader和jsonwriter。

JSONMapper实际上是建立在以上两个类的基础上的,所以你可以把这两个类当成是litJSON的底层接口。

使用JsonReader

[csharp] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. using LitJson;  
  2. using System;  
  3.   
  4. public class DataReader  
  5. {  
  6.     public static void Main()  
  7.     {  
  8.         string sample = @"{  
  9.             ""name""  : ""Bill"",  
  10.             ""age""   : 32,  
  11.             ""awake"" : true,  
  12.             ""n""     : 1994.0226,  
  13.             ""note""  : [ ""life""""is""""but""""a""""dream"" ]  
  14.           }";  
  15.   
  16.         PrintJson(sample);  
  17.     }  
  18.   
  19.     public static void PrintJson(string json)  
  20.     {  
  21.         JsonReader reader = new JsonReader(json);  
  22.   
  23.         Console.WriteLine ("{0,14} {1,10} {2,16}""Token""Value""Type");  
  24.         Console.WriteLine (new String ('-', 42));  
  25.   
  26.         // The Read() method returns false when there's nothing else to read  
  27.         while (reader.Read()) {  
  28.             string type = reader.Value != null ?  
  29.                 reader.Value.GetType().ToString() : "";  
  30.   
  31.             Console.WriteLine("{0,14} {1,10} {2,16}",  
  32.                               reader.Token, reader.Value, type);  
  33.         }  
  34.     }  
  35. }  
输出如下:
Token      Value             Type
------------------------------------------ObjectStart                            PropertyName       name    System.StringString       Bill    System.StringPropertyName        age    System.StringInt         32     System.Int32PropertyName      awake    System.StringBoolean       True   System.BooleanPropertyName          n    System.StringDouble  1994.0226    System.DoublePropertyName       note    System.StringArrayStart                            String       life    System.StringString         is    System.StringString        but    System.StringString          a    System.StringString      dream    System.StringArrayEnd                            ObjectEnd
Unity中Json有多个{}的格式
string a = @"{""action"":""1"",
""msd"":""2"",
""terrainId"":""32131"",
""body"":{
""terrainId"":""5454"",
""type"":""1111"",
""scene"":""2222"",
""mouse"":""3333"",
""season"":""4444"",
""weather"":""5555"",
""hour"":""6666"",
""wind"":""7777"",
""lightValue"":""8888"",
""boo"":""9999"",
""Name"":""0"",
""PositionX"":""1"",
""PositionY"":""2"",
""PositionZ"":""3"",
""arm"":""4"",
""sight"":{
""type"":""a"",
""mass"":""b"",
""Vector"":""c"",
""int1"":""d"",
""int2"":""e""
},
""target"":{
""id"":""F1"",
""positionX"":""F2"",
""positionY"":""F3"",
""positionZ"":""F4"",
""Style"":""F5"",
""Speed"":""F6"",
""distance"":""F7"",
""number"":""F8""
}
}
}";


http://www.jmfq.cn/news/5014567.html

相关文章:

  • 我想给别人做网站/网络营销的三大核心
  • 用自己电脑做服务器建网站/百度搜索风云榜单
  • 杭州网站建设h5/网站模板源码
  • 做网站靠谱的公司/云南最新消息
  • 乾元坤和B2B网站建设解/seo建站还有市场吗
  • 吉林省住房城乡建设厅网站/新乡seo推广
  • 大兴网站建设制作/千牛怎么做免费推广引流
  • 网站全面详细创建步骤/有哪些搜索引擎网站
  • 怎么做外网网站监控/长沙网络公司排名
  • 北京网站制作基本流程/站外引流推广渠道
  • h5制作价格/安卓内核级优化神器
  • 建设学校网站策划书/免费发布信息网网站
  • 做网站数据库设计/手机优化软件哪个好用
  • 厦门做网站/推广策略都有哪些
  • 网站建设的工作内容/西安百度推广运营
  • 汕头企业自助建站/郑州搜索引擎优化公司
  • 品牌网站建设 蝌蚪小7/免费python在线网站
  • 内蒙能源建设集团网站/网络推广公司服务内容
  • 网站分为哪几种/seo投放
  • 网站开发需要用到哪些资料/steam交易链接可以随便给别人吗
  • 塑料袋销售做哪个网站推广好/北京网站优化方式
  • 罗定市住房和城乡建设局网站/湘潭网络推广
  • 做公司网站用什么系统/百度河南代理商
  • 扬州做网站的公司/今天的新闻大事10条
  • 网站数据丢失怎么办/湖南平台网站建设制作
  • 如何自学网站建设/国际军事新闻最新消息今天
  • wordpress修改网站名称/百度店铺
  • 做电力项目信息的网站/企业新闻营销
  • win2008做的网站打不开/自建站平台
  • 中国进出口企业名录/seo推广的方法