本文整理汇总了C#中LitJson.JsonReader类的典型用法代码示例。如果您正苦于以下问题:C# JsonReader类的具体用法?C# JsonReader怎么用?C# JsonReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonReader类属于LitJson命名空间,在下文中一共展示了JsonReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommentsTest
public void CommentsTest()
{
string json = @"
{
// This is the first property
""foo"" : ""bar"",
/**
* This is the second property
**/
""baz"": ""blah""
}";
JsonReader reader = new JsonReader (json);
reader.Read ();
reader.Read ();
Assert.AreEqual ("foo", (string) reader.Value, "A1");
reader.Read ();
reader.Read ();
Assert.AreEqual ("baz", (string) reader.Value, "A2");
reader.Read ();
reader.Read ();
Assert.IsTrue (reader.EndOfJson, "A3");
}
示例2: DoubleTest
public void DoubleTest()
{
string json = @"[ 0.0, -0.0, 3.1416, 8e-3, 7E-5, -128.000009,
144e+3, 0.1e2 ]";
JsonReader reader = new JsonReader (json);
reader.Read ();
reader.Read ();
Assert.AreEqual ((double) reader.Value, 0.0,
Double.Epsilon, "A1");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 0.0,
Double.Epsilon, "A2");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 3.1416,
Double.Epsilon, "A3");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 0.008,
Double.Epsilon, "A4");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 0.00007,
Double.Epsilon, "A5");
reader.Read ();
Assert.AreEqual ((double) reader.Value, -128.000009,
Double.Epsilon, "A6");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 144000.0,
Double.Epsilon, "A7");
reader.Read ();
Assert.AreEqual ((double) reader.Value, 10.0,
Double.Epsilon, "A8");
reader.Close ();
}
示例3: Read
public static ZenSettings Read(string filePath)
{
string src = File.ReadAllText(filePath);
src = SanitizeJSon(src);
JsonReader reader = new JsonReader(src);
return ReadZenSettings(reader);
}
示例4: DeserializeJson
public static OSD DeserializeJson(Stream json)
{
using (StreamReader streamReader = new StreamReader(json))
{
JsonReader reader = new JsonReader(streamReader);
return DeserializeJson(JsonMapper.ToObject(reader));
}
}
示例5: ReadModules
private void ReadModules(JsonReader reader)
{
while (reader.Read())
{
if (reader.Token == JsonToken.ArrayEnd) break;
if (reader.Token == JsonToken.ObjectStart) ReadModule(reader);
}
}
示例6: LitJsonReaderStrings
public static void LitJsonReaderStrings ()
{
for (int i = 0; i < Common.Iterations; i++) {
JsonReader reader = new JsonReader (Common.JsonStrings);
while (reader.Read ());
}
}
示例7: WriteJsonData
public static void WriteJsonData(this JsonWriter writer, JsonData jsonData)
{
var reader = new JsonReader(jsonData.ToJson());
while (reader.Read())
{
switch (reader.Token)
{
case JsonToken.None:
break;
case JsonToken.ObjectStart:
writer.WriteObjectStart();
break;
case JsonToken.PropertyName:
writer.WritePropertyName(reader.Value.ToString());
break;
case JsonToken.ObjectEnd:
writer.WriteObjectEnd();
break;
case JsonToken.ArrayStart:
writer.WriteArrayStart();
break;
case JsonToken.ArrayEnd:
writer.WriteArrayEnd();
break;
case JsonToken.Int:
writer.Write((int)reader.Value);
break;
case JsonToken.Long:
writer.Write((long)reader.Value);
break;
case JsonToken.ULong:
writer.Write((ulong)reader.Value);
break;
case JsonToken.Double:
writer.Write((double)reader.Value);
break;
case JsonToken.String:
writer.Write((string)reader.Value);
break;
case JsonToken.Boolean:
writer.Write((bool)reader.Value);
break;
case JsonToken.Null:
break;
default:
break;
}
}
}
示例8: BooleanTest
public void BooleanTest()
{
string json = "[ true, false ]";
JsonReader reader = new JsonReader (json);
reader.Read ();
reader.Read ();
Assert.IsTrue ((bool) reader.Value, "A1");
reader.Read ();
Assert.IsTrue (! ((bool) reader.Value), "A2");
reader.Close ();
}
示例9: ReadModule
private void ReadModule(JsonReader reader)
{
// root/modules
string prop = null;
while (reader.Read())
{
if (reader.Token == JsonToken.ObjectEnd) break;
if (reader.Token == JsonToken.PropertyName) prop = reader.Value.ToString();
else if (reader.Token == JsonToken.ArrayStart)
{
if (prop == "types") ReadTypes(reader);
else reader.SkipArray();
}
else if (reader.Token == JsonToken.ObjectStart) {
reader.SkipObject();
}
}
}
示例10: LitJsonReaderFirstProperty
public static void LitJsonReaderFirstProperty ()
{
for (int i = 0; i < Common.Iterations; i++) {
bool found = false;
JsonReader reader = new JsonReader (Common.JsonText);
while (reader.Read ()) {
if (reader.Token == JsonToken.PropertyName &&
(string) reader.Value == "FirstProperty") {
found = true;
break;
}
}
if (! found)
Console.WriteLine ("FirstProperty not found!");
}
}
示例11: ReadZenSettings
private static ZenSettings ReadZenSettings(JsonReader reader)
{
ZenSettings settings = new ZenSettings();
Type objType = settings.GetType();
reader.Read();
if (reader.Token != JsonToken.ObjectStart)
return null;
string currentProp = null;
while (reader.Read())
{
if (reader.Token == JsonToken.ObjectEnd) break;
if (reader.Token == JsonToken.PropertyName)
currentProp = reader.Value.ToString();
else if (reader.Token == JsonToken.ObjectStart)
{
if (currentProp == "variables") settings.variables = ReadHashtable(reader);
else settings.langs.Add(currentProp, ReadZenLang(reader));
}
}
foreach (ZenLang lang in settings.langs.Values)
{
if (lang.extends != null && settings.langs.ContainsKey(lang.extends))
ExtendLang(lang, settings.langs[lang.extends]);
}
if (!settings.langs.ContainsKey("xml"))
{
ZenLang xlang = new ZenLang();
xlang.abbreviations = new Hashtable();
xlang.element_types = new ZenElementTypes(null);
xlang.filters = "xml, xsl";
xlang.snippets = new Hashtable();
settings.langs.Add("xml", xlang);
}
settings.variables["child"] = "";
return settings;
}
示例12: ReadObject
public static void ReadObject(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
{
System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ObjectStart);
if (begin != null)
{
begin(context);
}
// parse the properties
reader.Read();
while (reader.Token != JsonToken.ObjectEnd)
{
parser(reader, context);
reader.Read();
}
if (end != null)
{
end(context);
}
}
示例13: Reader
private Reader(JsonReader json, string bundlePath, bool createdForThisInstance)
{
if (json == null)
{
throw new ArgumentNullException("json");
}
this.json = json;
this.disposesTextReader = createdForThisInstance;
this.prefix = bundlePath;
if (!string.IsNullOrEmpty(this.prefix))
{
char chr = this.prefix[this.prefix.Length - 1];
if (chr != '/' && chr != '\\')
{
this.prefix = string.Concat(this.prefix, "/");
}
}
else
{
this.prefix = string.Empty;
}
}
示例14: Run
private void Run()
{
using (StreamReader sr = new StreamReader(path.Path))
{
string raw = sr.ReadToEnd();
sr.Close();
JsonReader reader = new JsonReader(raw);
try
{
if (reader.Read() && reader.Token == JsonToken.ObjectStart)
{
files = new Dictionary<string, FileModel>();
BuildModel(reader);
path.SetFiles(files);
}
}
catch (Exception ex)
{
TraceManager.AddAsync(ex.Message);
}
}
}
示例15: JsonWebTokenHeader
public JsonWebTokenHeader(string originalData)
{
_originalData = originalData;
var reader = new JsonReader(originalData.Base64UrlDecode(Encoding.UTF8));
while (reader.Read())
{
if (reader.Token == JsonToken.PropertyName)
{
switch (reader.Value.ToString())
{
case "alg":
reader.Read();
SetAlgorithm((string)reader.Value);
break;
case "kid":
reader.Read();
KeyId = (string)reader.Value;
break;
case "xdu":
reader.Read();
KeyFormat = KeyFormat.Rfc4050;
KeyUri = new Uri((string)reader.Value);
break;
case "jku":
reader.Read();
KeyFormat = KeyFormat.Json;
KeyUri = new Uri((string)reader.Value);
break;
case "xku":
reader.Read();
KeyFormat = KeyFormat.X509;
KeyUri = new Uri((string)reader.Value);
break;
}
}
}
}