本文整理汇总了C#中LitJson.JsonReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Read方法的具体用法?C# JsonReader.Read怎么用?C# JsonReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LitJson.JsonReader
的用法示例。
在下文中一共展示了JsonReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ();
}
示例2: 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 ();
}
示例3: ReadModules
private void ReadModules(JsonReader reader)
{
while (reader.Read())
{
if (reader.Token == JsonToken.ArrayEnd) break;
if (reader.Token == JsonToken.ObjectStart) ReadModule(reader);
}
}
示例4: LitJsonReaderStrings
public static void LitJsonReaderStrings ()
{
for (int i = 0; i < Common.Iterations; i++) {
JsonReader reader = new JsonReader (Common.JsonStrings);
while (reader.Read ());
}
}
示例5: 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;
}
示例6: 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");
}
示例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: ReadArray
public static void ReadArray(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
{
System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ArrayStart);
// parse the elements
reader.Read();
while (reader.Token != JsonToken.ArrayEnd)
{
if (reader.Token == JsonToken.ObjectStart)
{
ReadObject(reader, context, begin, parser, end);
}
else if (reader.Token == JsonToken.ArrayStart)
{
ReadArray(reader, context, parser);
}
else
{
parser(reader, context);
}
reader.Read();
}
}
示例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: 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);
}
}
}
示例12: JsonKeyControlLoader
public JsonKeyControlLoader(JsonReader reader)
{
dummyKeyControl = new DummyKeyControl();
JsonMapper jsonMapper = new JsonMapper();
while (reader.Read())
{
if (reader.Token == JsonToken.ObjectEnd)
{
break;
}
if (reader.Token == JsonToken.PropertyName)
{
switch (reader.Value as string)
{
case "walkKeyBinding":
dummyKeyControl.walkKeyBinding = jsonMapper.ToObject<Dictionary<string, string>>(reader);
break;
case "layBombKey":
dummyKeyControl.layBombKey = jsonMapper.ToObject<string>(reader);
break;
}
}
}
}
示例13: 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;
}
}
}
}
示例14: ReadProperty
private void ReadProperty(JsonReader reader, ClassModel cClass)
{
MemberModel member = new MemberModel();
member.Flags = FlagType.Variable;
MemberModel getter = null;
MemberModel setter = null;
string prop = null;
string name = null;
string doc = null;
while (reader.Read())
{
if (reader.Token == JsonToken.ObjectEnd) break;
if (reader.Token == JsonToken.PropertyName) prop = reader.Value.ToString();
else if (reader.Token == JsonToken.String)
{
string val = reader.Value.ToString();
switch (prop)
{
case "name": name = val; break;
case "docstring": doc = ExtractDoc(val); break;
}
}
else if (reader.Token == JsonToken.ArrayStart)
{
switch (prop)
{
//case "propertyattributes": ReadAttributes(reader, member); break;
//case "metainfo": reader.SkipArray(); break;
default: reader.SkipArray(); break;
}
}
else if (reader.Token == JsonToken.ObjectStart)
{
switch (prop)
{
case "getter":
getter = ReadMethod(reader, cClass);
getter.Flags |= FlagType.Getter;
break;
case "setter":
setter = ReadMethod(reader, cClass);
setter.Flags |= FlagType.Setter;
break;
default: reader.SkipObject(); break;
}
}
}
if (getter != null)
{
getter.Name = name;
getter.Comments = doc;
getter.Flags &= ~FlagType.Function;
}
if (setter != null)
{
setter.Name = name;
if (getter == null) setter.Comments = doc;
setter.Flags &= ~FlagType.Function;
}
}
示例15: ReadMethod
private MemberModel ReadMethod(JsonReader reader, ClassModel cClass)
{
MemberModel member = new MemberModel();
member.Flags = FlagType.Function;
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.String)
{
string val = reader.Value.ToString();
switch (prop)
{
case "name":
if (!val.StartsWith("__op_")) {
member.Name = val;
cClass.Members.Add(member);
}
break;
case "returntype": if (member.Type == null) member.Type = CleanType(val); break;
case "docstring": member.Comments = ExtractDoc(val); break;
}
}
else if (reader.Token == JsonToken.ArrayStart)
{
switch (prop)
{
case "methodattributes":
ReadAttributes(reader, member);
if ((member.Flags & FlagType.Static) == 0) member.Flags |= FlagType.Dynamic;
break;
case "parameters": ReadParameters(reader, member); break;
case "metainfo": ReadMetas(reader, member); break;
default: reader.SkipArray(); break;
}
}
else if (reader.Token == JsonToken.ObjectStart)
{
switch (prop)
{
case "templatetypes": ReadTemplateTypes(reader, member); break;
default: reader.SkipObject(); break;
}
}
}
return member;
}