验证中...
Languages: C#
Categories: 其他
Latest update 2018-07-12 17:35
JSON格式化操作
Raw Copy
/// <summary>
/// json格式化操作
/// </summary>
/// <param name="jsonStr"></param>
/// <returns></returns>
internal static string JsonFormater(this string jsonStr)
{
JsonSerializer serializer = new JsonSerializer();
TextReader tr = new StringReader(jsonStr);
JsonTextReader reader = new JsonTextReader(tr);
object obj = serializer.Deserialize<dynamic>(reader);
if (obj != null)
{
using (StringWriter writer = new StringWriter())
{
JsonTextWriter jsonWriter = new JsonTextWriter(writer)
{
Formatting = Formatting.Indented,
Indentation = 4,
IndentChar = ' '
};
serializer.Serialize(jsonWriter, obj);
return writer.ToString();
};
}
return "";
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search