zoukankan      html  css  js  c++  java
  • C#将字符串格式化为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;
               }         
           }
  • 相关阅读:
    Bootsrap 的 Carousel
    Bootstrap 的 Tooltip 和 Popover
    JavaScript 继承
    Bootstrap 的 Collapse
    Bootstrap 组件之 Panel
    Bootstrap 组件之 List group
    Bootstrap 组件之 Nav
    使用 classList API
    Bootstrap 的 Dropdown
    Bootstrap 的 Modal
  • 原文地址:https://www.cnblogs.com/LCLBook/p/11137384.html
Copyright © 2011-2022 走看看