本文整理汇总了C#中JArray.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.ToString方法的具体用法?C# JArray.ToString怎么用?C# JArray.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JArray
的用法示例。
在下文中一共展示了JArray.ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: vaildData
public static void vaildData()
{
JArray ja = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"input/mergeresult_final.json"));
JArray jaTemp = new JArray();
DirectoryInfo dirInfo = new DirectoryInfo(@"C:\Users\GIS-615\SkyDrive\论文&项目\研究生毕业论文\数据\GetPoiTimeLineWithAzure\原始数据");
foreach (JObject jo in ja)
{
int count = 0;
foreach (FileInfo file in dirInfo.GetFiles())
{
string filename = file.Name.Substring(0, file.Name.Length - 5);
if (jo["poiid"].ToString().Equals(filename))
{
count++;
break;
}
}
if (count == 0)
{
jaTemp.Add(jo);
}
}
File.WriteAllText(@"output//nullData.json", jaTemp.ToString());
}
示例2: Manual
public void Manual()
{
JArray array = new JArray();
JValue text = new JValue("Manual text");
JValue date = new JValue(new DateTime(2000, 5, 23));
array.Add(text);
array.Add(date);
string json = array.ToString();
// [
// "Manual text",
// "\/Date(958996800000+1200)\/"
// ]
}
示例3: Example
public void Example()
{
#region Usage
IList<BlogPost> blogPosts = new List<BlogPost>
{
new BlogPost
{
Title = "Json.NET is awesome!",
AuthorName = "James Newton-King",
AuthorTwitter = "JamesNK",
PostedDate = new DateTime(2013, 1, 23, 19, 30, 0),
Body = @"<h3>Title!</h3>
<p>Content!</p>"
}
};
JArray blogPostsArray = new JArray(
blogPosts.Select(p => new JObject
{
{ "Title", p.Title },
{
"Author", new JObject
{
{ "Name", p.AuthorName },
{ "Twitter", p.AuthorTwitter }
}
},
{ "Date", p.PostedDate },
{ "BodyHtml", HttpUtility.HtmlEncode(p.Body) },
})
);
Console.WriteLine(blogPostsArray.ToString());
// [
// {
// "Title": "Json.NET is awesome!",
// "Author": {
// "Name": "James Newton-King",
// "Twitter": "JamesNK"
// },
// "Date": "2013-01-23T19:30:00",
// "BodyHtml": "<h3>Title!</h3>\r\n<p>Content!</p>"
// }
// ]
#endregion
}
示例4: GetUser
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string GetUser(string query_loginName, string query_username)
{
JArray ja = new JArray();
try
{
using (venuesEntities db = new venuesEntities())
{
string strSql = "SELECT su.User_Id,su.User_LoginName,su.User_Name,su.User_Password,sd.DA_Name,sd.DA_Code,su.User_TypeId FROM tbl_sys_user AS su LEFT JOIN tbl_sys_dictionary AS sd ON su.User_TypeId=sd.DA_Id where 1=1 ";
if (query_loginName != "")
{
strSql += " and su.User_LoginName='" + query_loginName + "'";
}
else if (query_username != "")
{
strSql += " and su.User_Name='" + query_username + "'";
}
ObjectQuery<DbDataRecord> results = db.CreateQuery<DbDataRecord>(strSql);
foreach (var item in results)
{
ja.Add(
new JObject(
new JProperty("User_Id", item["User_Id"].ToString()),
new JProperty("User_LoginName", item["User_LoginName"].ToString()),
new JProperty("User_Name", item["User_Name"].ToString()),
new JProperty("User_Password", item["User_Password"].ToString()),
new JProperty("DA_Name", item["DA_Name"].ToString()),
new JProperty("User_TypeId", item["User_TypeId"].ToString()),
new JProperty("DA_Code", item["DA_Code"].ToString())
)
);
};
}
}
catch (Exception e)
{
addLog(KeyManager.LogTypeId_Error, KeyManager.CUR_USERID, KeyManager.MENUS.Menu_SystemUsersManager, "查询用户列表,User_LoginName=" + query_loginName + ",User_Name=" + query_username + ",错误信息:" + e.Message);
}
addLog(KeyManager.LogTypeId_Option, KeyManager.CUR_USERID, KeyManager.MENUS.Menu_SystemUsersManager, "查询用户列表,User_LoginName=" + query_loginName + ",User_Name=" + query_username);
return ja.ToString();
}
示例5: DiffCategories
private static void DiffCategories()
{
//type1
int[] typeArray = new int[]{
33,
116,179,180,182,183,
184,185,186,187,188,
195,196,197,198,
199,200,201,202,203,
204,205,206,207,208,
234,239,240,243,244,
245,246,607
};
//去掉252,254,20,156,219,45,52,671,678,189, 220,221,222,223,224,
//225,226,227,228,229,230,231,232,233,235,236,237,238,250,604,677,627,628
List<int> typeList = new List<int>(typeArray);
JArray ja = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"../../output/type1/typetrue.json"));
//foreach (int num in typeList)
//{
int num = 252;
string path = @"../../output/45/";
//if (!Directory.Exists(path))
//{
// Directory.CreateDirectory(path);
//}
JArray jaType = new JArray();
foreach (JObject jo in ja)
{
if (Int32.Parse(jo["category"].ToString()) == num)
{
jaType.Add(jo);
Console.WriteLine("jaType :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
streamWriter.WriteLine("jaType :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
}
Console.WriteLine("jaType:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaType.Count.ToString());
streamWriter.WriteLine("jaType:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaType.Count.ToString());
File.WriteAllText(path + "/" + num + ".json", jaType.ToString());
}
//}
}
示例6: CreateJTokenTree
public void CreateJTokenTree()
{
JObject o =
new JObject(
new JProperty("Test1", "Test1Value"),
new JProperty("Test2", "Test2Value"),
new JProperty("Test3", "Test3Value"),
new JProperty("Test4", null)
);
Assert.AreEqual(4, o.Properties().Count());
Assert.AreEqual(@"{
""Test1"": ""Test1Value"",
""Test2"": ""Test2Value"",
""Test3"": ""Test3Value"",
""Test4"": null
}", o.ToString());
JArray a =
new JArray(
o,
new DateTime(2000, 10, 10, 0, 0, 0, DateTimeKind.Utc),
55,
new JArray(
"1",
2,
3.0,
new DateTime(4, 5, 6, 7, 8, 9, DateTimeKind.Utc)
),
new JConstructor(
"ConstructorName",
"param1",
2,
3.0
)
);
Assert.AreEqual(5, a.Count());
Assert.AreEqual(@"[
{
""Test1"": ""Test1Value"",
""Test2"": ""Test2Value"",
""Test3"": ""Test3Value"",
""Test4"": null
},
""2000-10-10T00:00:00Z"",
55,
[
""1"",
2,
3.0,
""0004-05-06T07:08:09Z""
],
new ConstructorName(
""param1"",
2,
3.0
)
]", a.ToString());
}
示例7: ToStringWithNoIndenting
public void ToStringWithNoIndenting()
{
JArray a =
new JArray(
new JValue(new DateTime(2009, 2, 15, 0, 0, 0, DateTimeKind.Utc))
);
string json = a.ToString(Formatting.None, new IsoDateTimeConverter());
Assert.AreEqual(@"[""2009-02-15T00:00:00Z""]", json);
}
示例8: ToStringWithConverters
public void ToStringWithConverters()
{
JArray a =
new JArray(
new JValue(new DateTime(2009, 2, 15, 0, 0, 0, DateTimeKind.Utc))
);
string json = a.ToString(Formatting.Indented, new IsoDateTimeConverter());
Assert.AreEqual(@"[
""2009-02-15T00:00:00Z""
]", json);
json = JsonConvert.SerializeObject(a, new IsoDateTimeConverter());
Assert.AreEqual(@"[""2009-02-15T00:00:00Z""]", json);
}
示例9: ToStringNewTypes
public void ToStringNewTypes()
{
#if NET40
var a = new JArray(
new JValue(new DateTimeOffset(2013, 02, 01, 01, 02, 03, 04, TimeSpan.FromHours(1))),
new JValue(new BigInteger(5)),
new JValue(1.1f)
);
StringAssert.Equal(@"[
""2013-02-01T01:02:03.004+01:00"",
5,
1.1
]", a.ToString());
#else
var a = new JArray(
new JValue(new DateTimeOffset(2013, 02, 01, 01, 02, 03, 04, TimeSpan.FromHours(1))),
new JValue(1.1f)
);
StringAssert.Equal(@"[
""2013-02-01T01:02:03.004+01:00"",
1.1
]", a.ToString());
#endif
}
示例10: LinqToJsonCreateNormal
public void LinqToJsonCreateNormal()
{
#region LinqToJsonCreateNormal
JArray array = new JArray();
JValue text = new JValue("Manual text");
JValue date = new JValue(new DateTime(2000, 5, 23));
array.Add(text);
array.Add(date);
string json = array.ToString();
// [
// "Manual text",
// "2000-05-23T00:00:00"
// ]
#endregion
}
示例11: MergeData
/// <summary>
/// 数据整合
/// </summary>
private static void MergeData()
{
DirectoryInfo rootDir = new DirectoryInfo(@"../../" + "input");
JArray jaAll = new JArray();
List<string> poiIdList = new List<string>();
try
{
//遍历文件
foreach (FileInfo file in rootDir.GetFiles("*.*"))
{
string readText = File.ReadAllText(file.Directory + "\\" + file.Name);
JArray ja = (JArray)JsonConvert.DeserializeObject(readText);
foreach (JObject joTemp in ja)
{
//Scenic scenic = JsonConvert.DeserializeObject<Scenic>(jo.ToString());
if (jaAll.Count == 0)
{
jaAll.Add(joTemp);
poiIdList.Add(joTemp["poiid"].ToString());
}
else
{
if (!poiIdList.Contains(joTemp["poiid"].ToString()))
{
jaAll.Add(joTemp);
poiIdList.Add(joTemp["poiid"].ToString());
}
}
}
streamWriter.WriteLine("File: " + DateTime.Now.ToLocalTime().ToString() + " ; " + file.ToString() + " ; " + ja.Count);
Console.WriteLine("File: " + DateTime.Now.ToLocalTime().ToString() + " ; " + file.ToString() + " ; " + ja.Count);
}
File.WriteAllText(@"../../" + "/output/result.json", jaAll.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Error :" + DateTime.Now.ToLocalTime().ToString() + " ; " + ex.Message.ToString());
streamWriter.WriteLine("Error :" + DateTime.Now.ToLocalTime().ToString() + " ; " + ex.Message.ToString());
}
}
示例12: ValidatePoiType
private static void ValidatePoiType()
{
//type1
//int[] typeArray = new int[]{
// 33,254,20,156,219,
// 45,252,52,671,678,
// 116,179,180,182,183,
// 184,185,186,187,188,
// 189,195,196,197,198,
// 199,200,201,202,203,
// 204,205,206,207,208,
// 220,221,222,223,224,
// 225,226,227,228,229,
// 230,231,232,233,234,
// 235,236,237,238,239,
// 240,243,244,245,246,
// 250,604,607,677,627,
// 628
//};
//type2
int[] typeArray = new int[]{
33,
116,179,180,182,183,
184,185,186,187,188,
195,196,197,198,
199,200,201,202,203,
204,205,206,207,208,
234,239,240,243,244,
245,246,607
};
List<int> typeList = new List<int>(typeArray);
JArray ja = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"../../output/mergeresult.json"));
JArray jaTypeTrue = new JArray();
JArray jaTypeFalse = new JArray();
JArray jaTypeNull = new JArray();
foreach (JObject jo in ja)
{
if (typeList.Contains(Int32.Parse(jo["category"].ToString())))
{
jaTypeTrue.Add(jo);
Console.WriteLine("TypeTrue :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
streamWriter.WriteLine("TypeTrue :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
}
else if (Int32.Parse(jo["category"].ToString()) == 500)
{
jaTypeNull.Add(jo);
Console.WriteLine("TypeNull :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
streamWriter.WriteLine("TypeNull :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
}
else
{
jaTypeFalse.Add(jo);
Console.WriteLine("TypeFalse :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
streamWriter.WriteLine("TypeFalse :" + DateTime.Now.ToLocalTime().ToString() + ";" + jo["title"].ToString() + ";" + jo["poiid"].ToString());
}
}
Console.WriteLine("TypeFalseCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeFalse.Count.ToString());
streamWriter.WriteLine("TypeFalseCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeFalse.Count.ToString());
Console.WriteLine("TypeTrueCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeTrue.Count.ToString());
streamWriter.WriteLine("TypeTrueCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeTrue.Count.ToString());
Console.WriteLine("TypeNullCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeNull.Count.ToString());
streamWriter.WriteLine("TypeNullCount:" + DateTime.Now.ToLocalTime().ToString() + ";" + jaTypeNull.Count.ToString());
File.WriteAllText(@"../../" + "/output/typefalse.json", jaTypeFalse.ToString());
File.WriteAllText(@"../../" + "/output/typetrue.json", jaTypeTrue.ToString());
File.WriteAllText(@"../../" + "/output/typenull.json", jaTypeNull.ToString());
}