コード例 #1
0
        public static Entities.ScraperTask DeSerializeFromJsonStringTSK(string json)
        {
            using (Newtonsoft.Json.JsonReader jr = new JsonTextReader(new StringReader(json)))
            {
                Entities.ScraperTask psrr = serializer.Deserialize <Entities.ScraperTask>(jr);

                return(psrr);
            }
        }
コード例 #2
0
 public static Entities.ScraperTask DeSerializeTSK(string fileName)
 {
     using (StreamReader srr = new StreamReader(fileName))
     {
         using (Newtonsoft.Json.JsonReader jr = new JsonTextReader(srr))
         {
             Entities.ScraperTask psrr = serializer.Deserialize <Entities.ScraperTask>(jr);
             return(psrr);
         }
     }
 }
コード例 #3
0
 public static void Serialize(string filename, Entities.ScraperTask tsk)
 {
     using (StreamWriter sw = new StreamWriter(filename))
         using (JsonWriter writer = new JsonTextWriter(sw)
         {
             Formatting = Formatting.Indented,
             Indentation = 4,
             IndentChar = ' '
         })
         {
             serializer.Serialize(writer, tsk);
         }
 }
コード例 #4
0
 public static string ConvertJsonStringFromTSK(Entities.ScraperTask obj)
 {
     //格式化json字符串
     //JsonSerializer serializer = new JsonSerializer();
     //TextReader tr = new StringReader(psr);
     //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("Error!转换Json错误,对象为空");
     }
 }
コード例 #5
0
 public static string ShowJson(Entities.ScraperTask tsk)
 {
     return(ConvertJsonStringFromTSK(tsk));
 }