• C# winform格式化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);

    }

  • 相关阅读:
    bzoj1336: [Balkan2002]Alien最小圆覆盖
    bzoj3564: [SHOI2014]信号增幅仪
    [HDU5353]
    [codeforce1072D]
    [dp001]逛公园
    树上问题泛做
    [BZOJ2599]race
    [CEOI2019]MAGIC TREE
    [BZOJ2836]魔法树
    QTREE3
  • 原文地址:https://www.cnblogs.com/tuxer/p/12869126.html
Copyright © 2020-2023  润新知