本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.GetEnumerator方法的具体用法?C# JObject.GetEnumerator怎么用?C# JObject.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.GetEnumerator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitObject
JToken VisitObject(JObject jObject)
{
var e = jObject.GetEnumerator();
bool addComma = false;
sb.Append("{");
while (e.MoveNext())
{
var kv = e.Current;
if (addComma)
sb.Append(", ");
else
addComma = true;
sb.Append(kv.Key);
sb.Append(": ");
Visit(kv.Value);
}
sb.Append("}");
return jObject;
}
示例2: ApplyConfig
public void ApplyConfig(JObject values)
{
IEnumerator<KeyValuePair<string, JToken>> it = values.GetEnumerator();
while (it.MoveNext())
{
switch (it.Current.Key)
{
case "prefix": Prefix = it.Current.Value.ToString(); break;
case "name": Name = it.Current.Value.ToString(); break;
case "title": Title = it.Current.Value.ToString(); break;
case "pagebreak": Pagebreak = (bool)it.Current.Value; break;
case "notitle": Notitle = (bool)it.Current.Value; break;
case "noheader": Noheader = (bool)it.Current.Value; break;
case "wiki": Wiki = it.Current.Value.ToString(); break;
case "entrypicture": EntryPicture = (bool)it.Current.Value; break;
}
}
}
示例3: AssertJsonAreEqual
private static void AssertJsonAreEqual(JObject expectedJson, JObject actualJson, string path)
{
Assert.AreEqual(expectedJson.Count, actualJson.Count, "Count of json object at " + path);
for (var expectedElementsEnumerator = expectedJson.GetEnumerator(); expectedElementsEnumerator.MoveNext(); )
{
JToken actualElement = null;
Assert.IsTrue(actualJson.TryGetValue(expectedElementsEnumerator.Current.Key, out actualElement), "Couldn't find " + path + "[" + expectedElementsEnumerator.Current.Key + "]");
AssertJsonAreEqual(expectedElementsEnumerator.Current.Value, actualElement, path + "[" + expectedElementsEnumerator.Current.Key + "]");
}
}
示例4: PutFolderData
private void PutFolderData(String folder, JObject data)
{
IEnumerator<KeyValuePair<String, JToken>> enumer = data.GetEnumerator();
foreach (String fileName in Directory.GetFiles(folder, "*.js"))
{
File.Delete(fileName);
}
while (enumer.MoveNext())
{
String fileName = enumer.Current.Key + ".js";
String content = enumer.Current.Value.Value<String>();
StreamWriter sw = new StreamWriter(System.IO.Path.Combine(folder, fileName), false, Encoding.UTF8);
sw.Write(content);
sw.Close();
}
}
示例5: buildElements
protected List<TJSONPair> buildElements(JObject o)
{
try {
String pname;
List<TJSONPair> res = new List<TJSONPair>();
IEnumerator<KeyValuePair<String,JToken>> keys = o.GetEnumerator();
while (keys.MoveNext())
{
pname = keys.Current.Key;
JToken jtk = keys.Current.Value;
JTokenType jttype = keys.Current.Value.Type;
switch (jttype) {
case JTokenType.Null: {
res.Add(new TJSONPair(pname, new TJSONNull()));
break;
}
case JTokenType.String:
{
res.Add(new TJSONPair(pname, new TJSONString(jtk.Value<string>())));
break;
}
case JTokenType.Float:
{
res.Add(new TJSONPair(pname, new TJSONNumber(jtk.Value<float>())));
break;
}
case JTokenType.Integer:
{
res.Add(new TJSONPair(pname, new TJSONNumber(jtk.Value<Int32>())));
break;
}
case JTokenType.Array:
{
res.Add(new TJSONPair(pname, new TJSONArray(jtk.Value<JArray>())));
break;
}
case JTokenType.Object:
{
res.Add(new TJSONPair(pname, new TJSONObject(jtk.Value<JObject>())));
break;
}
case JTokenType.Boolean:
{
if (jtk.Value<bool>())
res.Add(new TJSONPair(pname, new TJSONTrue()));
else
res.Add(new TJSONPair(pname, new TJSONFalse()));
break;
}
}
}
return res;
} catch (Exception) {
return null;
}
}