Skip to content

Flex-Xuan/MojoUnityJson

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MojoUnityJson v1.1.8

MojoUnityJson is an extremely simple and super fast JSON parser for c#. The core parsing code only 450 lines, and supports all standard Json formats. Also the MojoUnityJson provides simple APIs for visit different types of the Json values. The implementation only use the core .NET lib. Currently, the MojoUnityJson just has one file that can be easily integrated into any C# project.

License

MojoUnityJson is licensed under the MIT License.

How to use

  • Parsing Json string

    var jsonValue = MojoUnity.Json.Parse(jsonString);
  • JsonValue API

    • JsonValue is string
      public string AsString();
    • JsonValue is float
      public float AsFloat();
    • JsonValue is int
      public int AsInt();
    • JsonValue is bool
      public bool AsBool();
    • JsonValue is null
      public bool IsNull();
    • JsonValue is JsonObject
      /// Get the JsonObject, that is a set of k-v pairs, and each value is JsonValue.
      public Dictionary<string, JsonValue> AsObject();
      
      /// Get the JsonValue from JsonObject by key.
      public JsonValue AsObjectGet(string key);
      
      /// Get the JsonObject from JsonObject by key.
      public Dictionary<string, JsonValue> AsObjectGetObject(string key);
      
      /// Get the JsonArray from JsonObject by key.
      public List<JsonValue> AsObjectGetArray(string key);
      
      /// Get the string from JsonObject by key.
      public string AsObjectGetString(string key);
      
      /// Get the float from JsonObject by key.
      public float AsObjectGetFloat(string key);
      
      /// Get the int from JsonObject by key.
      public int AsObjectGetInt(string key);
      
      /// Get the bool from JsonObject by key.
      public bool AsObjectGetBool(string key);
      
      /// Get the null from JsonObject by key.  
      public bool AsObjectGetIsNull(string key);
    • JsonValue is JsonArray
      /// Get the JsonArray, that is JsonValue list.
      public List<JsonValue> AsArray();
      
      /// Get the JsonValue from JsonArray at index.
      public JsonValue AsArrayGet(int index);
      
      /// Get the JsonObject from JsonArray at index.
      public Dictionary<string, JsonValue> AsArrayGetObject(int index);
      
      /// Get the JsonArray from JsonArray at index.
      public List<JsonValue> AsArrayGetArray(int index);
      
      /// Get the string from JsonArray at index. 
      public string AsArrayGetString(int index);
      
      /// Get the float from JsonArray at index.
      public float AsArrayGetFloat(int index);
      
      /// Get the int from JsonArray at index.
      public int AsArrayGetInt(int index);
      
      /// Get the bool from JsonArray at index.
      public bool AsArrayGetBool(int index);
      
      /// Get the null from JsonArray at index.
      public bool AsArrayGetIsNull(int index);

How was born

The original implementation and core algorithm came from the Json.h of the pure C game engine Mojoc.

About

A simple and fast JSON parser for C#.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%