标签:rgs event info tchar button null reader string 格式化json
//格式化Json
private string ConvertStringToJson(string str)
{
//格式化json字符串
JsonSerializer serializer = new JsonSerializer();
TextReader tr = new StringReader(str);
JsonTextReader jtr = new JsonTextReader(tr);
object obj = serializer.Deserialize(jtr);
if (obj != null)
{
StringWriter textWriter = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
{
Formatting = Formatting.Indented,
Indentation = 4,
IndentChar = ‘ ‘
};
serializer.Serialize(jsonWriter, obj);
return textWriter.ToString();
}
else
{
return str;
}
}
private void button16_Click(object sender, EventArgs e)
{
string str = textBox2.Text;
textBox2.Text = ConvertStringToJson(str);
}
标签:rgs event info tchar button null reader string 格式化json
原文地址:https://www.cnblogs.com/tuxer/p/12869126.html