Web/Helpers/JsonHelper.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using ComLib;
namespace ComLib.Web.Helpers
{
/// <summary>
/// Helper class for Json related functionality.
/// </summary>
public class JsonHelper
{
/// <summary>
/// Escapes text to handle double quotes.
/// </summary>
/// <param name="text">Text to escape.</param>
/// <param name="encloseInQuotes">True to enclose in quotes.</param>
/// <returns>Escaped text.</returns>
public static string EscapeString(string text, bool encloseInQuotes = false)
{
if (string.IsNullOrEmpty(text))
return encloseInQuotes ? "\"\"" : string.Empty;
text = text.Replace("\\", "\\\\");
text = text.Replace("\"", "\\\"");
return encloseInQuotes ? "\"" + text + "\"" : text;
}
/// <summary>
/// Converts the paged items to list of json objects using the property metadata provided.
/// </summary>
/// <typeparam name="T">Type of paged items.</typeparam>
/// <param name="result">Paged list.</param>
/// <param name="_columnProps">Metadata.</param>
/// <param name="convertBoolToYesNo">True to convert booleans to yes/no.</param>
/// <returns>Json string.</returns>
public static string ConvertToJsonString<T>(PagedList<T> result, IList<PropertyInfo> _columnProps, bool convertBoolToYesNo = false)
{
StringBuilder buffer = new StringBuilder();
// Build up all the records.
for (int ndx = 0; ndx < result.Count; ndx++)
{
T item = result[ndx];
string propname = string.Empty;
object objval = null;
string val = string.Empty;
// Start the record
buffer.Append("{ ");
// Build up all the properties in each record.
for (int propNdx = 0; propNdx < _columnProps.Count; propNdx++)
{
PropertyInfo prop = _columnProps[propNdx];
objval = _columnProps[propNdx].GetValue(item, null);
后面还有 50 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
