月度归档:2012年11月

2的64次幂

0               1               0x1
1               2               0x2
2               4               0x4
3               8               0x8
4               16              0x10
5               32              0x20
6               64              0x40
7               128             0x80
8               256             0x100
9               512             0x200
10              1024            0x400
11              2048            0x800
12              4096            0x1000
13              8192            0x2000
14              16384           0x4000
15              32768           0x8000
16              65536           0x10000
17              131072          0x20000
18              262144          0x40000
19              524288          0x80000
20              1048576         0x100000
21              2097152         0x200000
22              4194304         0x400000
23              8388608         0x800000
24              16777216                0x1000000
25              33554432                0x2000000
26              67108864                0x4000000
27              134217728               0x8000000
28              268435456               0x10000000
29              536870912               0x20000000
30              1073741824              0x40000000
31              2147483648              0x80000000
32              4294967296              0x100000000
33              8589934592              0x200000000
34              17179869184             0x400000000
35              34359738368             0x800000000
36              68719476736             0x1000000000
37              137438953472            0x2000000000
38              274877906944            0x4000000000
39              549755813888            0x8000000000
40              1099511627776           0x10000000000
41              2199023255552           0x20000000000
42              4398046511104           0x40000000000
43              8796093022208           0x80000000000
44              17592186044416          0x100000000000
45              35184372088832          0x200000000000
46              70368744177664          0x400000000000
47              140737488355328         0x800000000000
48              281474976710656         0x1000000000000
49              562949953421312         0x2000000000000
50              1125899906842624                0x4000000000000
51              2251799813685248                0x8000000000000
52              4503599627370496                0x10000000000000
53              9007199254740992                0x20000000000000
54              18014398509481984               0x40000000000000
55              36028797018963968               0x80000000000000
56              72057594037927936               0x100000000000000
57              144115188075855872              0x200000000000000
58              288230376151711744              0x400000000000000
59              576460752303423488              0x800000000000000
60              1152921504606846976             0x1000000000000000
61              2305843009213693952             0x2000000000000000
62              4611686018427387904             0x4000000000000000
63              9223372036854775808             0x8000000000000000

Newtonsoft.Json序列化和反序列

这里下载:http://www.newtonsoft.com/products/json/
安装:
   1.解压下载文件,得到Newtonsoft.Json.dll
   2.在项目中添加引用..
 序列化和反序列在.net项目中:
 

Product product = new Product();
 
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
 
string output = javascriptConvert.SerializeObject(product);
//{
//  "Name": "Apple",
//  "Expiry": new Date(1230422400000),
//  "Price": 3.99,
//  "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}
 
Product deserializedProduct = (Product)javascriptConvert.DeserializeObject(output, typeof(Product));

 
读取JSON

string jsonText = "['JSON!',1,true,{property:'value'}]";
 
JsonReader reader = new JsonReader(new StringReader(jsonText));
 
Console.WriteLine("TokenType\t\tValueType\t\tValue");
 
while (reader.Read())
{
    Console.WriteLine(reader.TokenType + "\t\t" + WriteValue(reader.ValueType) + "\t\t" + WriteValue(reader.Value))
}

结果显示:

TokenType ValueType Value
StartArray null null
String System.String JSON!
Integer System.Int32 1
Boolean System.Boolean True
StartObject null null
PropertyName System.String property
String System.String value
EndObject null null
EndArray null null

JSON写入

StringWriter sw = new StringWriter();
JsonWriter writer = new JsonWriter(sw);
 
writer.WriteStartArray();
writer.WriteValue("JSON!");
writer.WriteValue(1);
writer.WriteValue(true);
writer.WriteStartObject();
writer.WritePropertyName("property");
writer.WriteValue("value");
writer.WriteEndObject();
writer.WriteEndArray();
 
writer.Flush();
 
string jsonText = sw.GetStringBuilder().ToString();
 
Console.WriteLine(jsonText);
// ['JSON!',1,true,{property:'value'}]

这里会打印出: ['JSON!',1,true,{property:'value'}].