JsonFx
JSON serialization framework for.NET
模組介紹 作者原文
[JsonFx v2.0][1] - JSON serialization framework for.NET
Distributed under the terms of an [MIT-style license][2]
Compatible Runtimes:
-.NET Framework 2.0, 3.0, 3.5, and 4.0
- Silverlight 3.0, 4.0
- Windows Phone 7
- Mono Framework 2.6
Serialization Features:
- Unified interface for reading / writing [JSON][3], [BSON][4], XML, [JsonML][5]
- Implements true LINQ-to-JSON (not simply LINQ-to-Objects over JSON types)
- Naturally deserializes to standard CLR types, not JSON/XML-specific types
- Supports reading/writing POCO classes
- Supports reading/writing using DataContract, XmlSerialization, JsonName, attributes
- Supports reading/writing using convention-based property renaming
- Supports reading/writing C# 4.0 dynamic types
- Supports reading/writing C# 3.0 Anonymous objects
- Supports reading/writing LINQ queries
- Supports custom reading/writing extensions & name resolution strategies
- Dependency-injection-friendly for extremely flexible custom configurations
- Stream-based serialization for reading/writing right off the wire
- Provider allows automatic selection of serializer from Content-Type and Accept-Types HTTP headers
Basic Examples:
Serialize to/from dynamic types (default for.NET 4.0):
var reader = new JsonReader(); var writer = new JsonWriter();
string input = @"{ ""foo"": true, ""array"": [ 42, false, ""Hello!"", null ] }";
dynamic output = reader.Read(input);
Console.WriteLine(output.array[0]); // 42
string json = writer.Write(output);
Console.WriteLine(json); // {"foo":true,"array":[42,false,"Hello!",null]}
Serialize to/from standard CLR types (default for.NET 2.0/3.5):
string input = @"{ ""first"": ""Foo"", ""last"": ""Bar"" }";
var output = reader.Read>(input);
Console.WriteLine(output["first"]); // Foo
output["middle"] = "Blah";
string json = writer.Write(output);
Console.WriteLine(json); // {"first":"Foo","last":"Bar","middle":"Blah"}
Serialize to/from Anonymous types
string input = @"{ ""first"": ""Foo"", ""last"": ""Bar"" }";
var template = new { first=String.Empty, middle=String.Empty, last=String.Empty };
var output = reader.Read(input, template);
Console.WriteLine(output.first); // Foo
output = new { output.first, middle="Blah", output.last };
string json = writer.Write(output);
Console.WriteLine(json); // {"first":"Foo","middle":"Blah","last":"Bar"}
Serialize to/from custom types and LINQ queries
[DataContract]
public class Person
{
[DataMember(Name="id")] public long PersonID { get; set; }
[DataMember(Name="first")] public string FirstName { get; set; }
[DataMember(Name="last")] public string LastName { get; set; }
}
// respect DataContracts on the way in
var reader = new JsonReader(new DataReaderSettings(new DataContractResolverStrategy()));
// use convention over configuration on the way out
var writer = new JsonWriter(new DataWriterSettings(new ConventionResolverStrategy(ConventionResolverStrategy.WordCasing.Lowercase, "-")));
string input =
@"[
{ ""id"": 1, ""first"": ""Foo"", ""last"": ""Bar"" },
{ ""id"": 2, ""first"": ""etc."", ""last"": ""et al."" },
{ ""id"": 3, ""first"": ""Blah"", ""last"": ""Yada"" }
]";
var people = reader.Query(input);
var query =
from person in people.ArrayItems()
where person.PersonID == 1 || person.FirstName == "Blah"
orderby person.PersonID
select person;
Console.WriteLine(query.Last().LastName); // Yada
string json = writer.Write(query);
Console.WriteLine(json); // [{"person-id":1,"first-name":"Foo","last-name":"Bar"},{"person-id":3,"first-name":"Blah","last-name":"Yada"}]
Serialize to/from TCP socket:
TcpClient tcpClient = new TcpClient(server, port);
NetworkStream tcpStream = tcpClient.GetStream();
// read incrementally from incoming stream
TextReader tcpReader = new StreamReader(tcpStream);
Foo myFoo = new JsonReader.Read(tcpReader);
// write directly to output stream
TextWriter tcpWriter = new StreamWriter(tcpStream);
new JsonWriter.Write(myFoo, tcpWriter);
Fully customizable name resolution strate
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。