JValue 1.8.2
dotnet add package JValue --version 1.8.2
NuGet\Install-Package JValue -Version 1.8.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JValue" Version="1.8.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JValue" Version="1.8.2" />
<PackageReference Include="JValue" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JValue --version 1.8.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JValue, 1.8.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=JValue&version=1.8.2
#tool nuget:?package=JValue&version=1.8.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JValue
Lightweight C# Json Parser.
JValue is simple and pure.
Features
- Pros
- Small memory footprint. (no heap allocation)
- Fastest parse.
- Easy to install.
- Easy to use.
- Unity3D friendly.
- Multithread safe. (JValue is immutable type)
- Cons
- When you get to repeat the same key, it is inefficient.
- Object mapping NOT supported. (
System.Reflection
)
Simple usage
JValue location = JValue.Parse(@"{""x"":10, ""y"":20}");
Console.WriteLine((int)location["x"]); // 10
Console.WriteLine((int)location["y"]); // 20
Console.WriteLine(location["z"].ToString()); // null
var person = new Dictionary<string, JValue>()
{
{"name", "John"},
{"age", 27},
};
Console.WriteLine(new JValue(person).ToString()); // {"name":"John","age":27}
Mechanism
JValue
isstruct
.JValue
has three members.{string source, int startIndex, int length}
// raw source
// {"name":"John", "age":27, "friend":{"name":"Tom"}}
JValue person = JValue.Parse(...);
// person.source = ...
// person.startIndex = 0
// person.length = 50
JValue name = person["name"];
// name.source = person.source
// name.startIndex = 8
// name.length = 6
JValue age = person["age"];
// age.source = person.source
// age.startIndex = 22
// age.length = 2
JValue friend = person["friend"];
// friend.source = person.source
// friend.startIndex = 35
// friend.length = 14
JValue friendName = friend["name"];
// friendName.source = friend.source = person.source
// friendName.startIndex = 43
// friendName.length = 5
string nameValue = (string)name; // At this time, encode string.
int ageValue = (int)age; // At this time, parse int.
Usage
JValue book = JValue.Parse(@"{
""name"": ""Json guide"",
""pages"": 400,
""tags"": [""computer"", ""data-interchange format"", ""easy""],
""price"": {""usd"":0.99, ""krw"":1000}
}");
string name = book["name"];
Console.WriteLine("Name: {0}", name);
int pages = book["pages"];
Console.WriteLine("Pages: {0}", pages);
Console.WriteLine("Primary tag: {0}", book["tags"][0].AsString());
Console.WriteLine("Tags:");
foreach (var item in book["tags"].Array())
Console.WriteLine("\t{0}", item);
Console.WriteLine("Unknown tag: {0}", book["tags"][100].AsString());
JValue price = book["price"];
Console.WriteLine("Price: ${0}", (double)price["usd"]);
Console.WriteLine("");
Console.WriteLine("Reserialization");
Console.WriteLine(book.Serialize(false));
/*
Name: Json guide
Pages: 400
Primary tag: computer
Tags:
"computer"
"data-interchange format"
"easy"
Unknown author:
Price: $0.99
Reserialization
{"name":"Json guide","pages":400,"tags":["computer","data-interchange format","easy"],"price":{"usd":0.99,"krw":1000}}
*/
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.