NingShenTian / Csharpjson
Licence: gpl-3.0
C# 编写的通用Json数据解析库
Stars: ✭ 16
Labels
Projects that are alternatives of or similar to Csharpjson
Winterfell
Generate complex, validated and extendable JSON-based forms in React.
Stars: ✭ 787 (+4818.75%)
Mutual labels: json
Jsonlite
A simple, self-contained, serverless, zero-configuration, json document store.
Stars: ✭ 819 (+5018.75%)
Mutual labels: json
Ason
[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare
Stars: ✭ 777 (+4756.25%)
Mutual labels: json
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+4643.75%)
Mutual labels: json
Jackson Module Kotlin
Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Stars: ✭ 830 (+5087.5%)
Mutual labels: json
Himotoki
A type-safe JSON decoding library purely written in Swift
Stars: ✭ 786 (+4812.5%)
Mutual labels: json
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+43943.75%)
Mutual labels: json
Telize
High performance JSON IP and GeoIP REST API (IP Geolocation)
Stars: ✭ 774 (+4737.5%)
Mutual labels: json
Portabletext
Portable Text is a JSON based rich text specification for modern content editing platforms.
Stars: ✭ 759 (+4643.75%)
Mutual labels: json
Rss Parser
A lightweight RSS parser, for Node and the browser
Stars: ✭ 793 (+4856.25%)
Mutual labels: json
Json to dart
Library that generates dart classes from json strings
Stars: ✭ 836 (+5125%)
Mutual labels: json
Yaml.js
Standalone JavaScript YAML 1.2 Parser & Encoder. Works under node.js and all major browsers. Also brings command line YAML/JSON conversion tools.
Stars: ✭ 810 (+4962.5%)
Mutual labels: json
基于C#的通用Json解析库!
GitHub:https://github.com/NingShenTian/CsharpJson
码云:https://gitee.com/xiaoguozhier/CsharpJson
1.说明:
1. 将JsonObject.cs、JsonArray.cs、JsonValue.cs、JsonDocument.cs 4个文件直接添加到你的项目中使用
2. 或将CsharpJson整个项目直接生成得到CsharpJson.dll通过引用的方式添加到项目中使用
3. 本Json库支持所有的C#版本包括Linux MonoDevelop,事实上该项目是在Ubuntu Linux上用MonoDevelop和WIndows下VS交替完成的。
2.具体使用:
生成Json:
using CsharpJson;
namespace test
{
class MainClass
{
public static void Main(string[] args)
{
JsonObject child = new JsonObject();
child["china"] = "hello";
child["shanghai"] = 123;
child.Add("one", "abc");
child.Add("two", 12);
child.Add("three", 44.9);
JsonArray arr = new JsonArray();
arr[0] = true;
arr[1] = 100;
arr[2] = "你好";
arr.Add("12");
arr.Add(456);
arr.Add(false);
arr.Add(child);
JsonObject obj = new JsonObject();
obj.Add("中国", "china");
obj.Add("北京", true);
obj.Add("上海", 123);
obj.Add("NULL",null);
obj.Add("childobj", child);
obj.Add("arrayvalue", arr);
JsonDocument doc=new JsonDocument();
doc.Object=obj;
string val = doc.ToJson();
Console.WriteLine("生成的Json字符串:");
Console.WriteLine(val);
}
}
}
执行结果:
生成的Json字符串:
{
"中国": "china",
"北京": true,
"上海": 123,
"childobj": {
"china": "hello",
"shanghai": 123,
"one": "abc",
"two": 12,
"three": 44.9
},
"arrayvalue": [
true,
100,
"你好",
"12",
456,
false,
{
"china": "hello",
"shanghai": 123,
"one": "abc",
"two": 12,
"three": 44.9
}
]
}
解析Josn:
string data = "{\"中国\": \"china\",\"北京\": true,\"上海\": 123}";
JsonDocument doc = JsonDocument.FromString(data);
if(doc.IsObject())
{
JsonObject jsobj = doc.Object;
foreach(string key in jsobj.Keys)
{
switch(jsobj[key].Valuetype)
{
case JsonType.BOOL:
Console.WriteLine("key={0},value={1}",key,jsobj[key].ToBool());
break;
case JsonType.NUMBER:
Console.WriteLine("key={0},value={1}",key,jsobj[key].ToInt());
break;
case JsonType.STRING:
Console.WriteLine("key={0},value={1}",key,jsobj[key].ToString());
break;
}
}
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].