/// <summary> /// Converts the specified model to json. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> internal static string Convert(JsonModel model) { var converter = new LiteJsonWriter(); using (var jsonWriter = new StringWriter()) { converter._writer = new JsonTextWriter(jsonWriter) { QuoteName = false, }; if (RafyEnvironment.IsDebuggingEnabled) { converter._writer.Formatting = Formatting.Indented; } //使用 JsonSerializer 会通过反射把对象的所有属性进行序列化,这时,不能对这个过程进行控制。 //var serializer = new JsonSerializer(); //serializer.Serialize(converter._writer, model); converter.WriteJsonModel(model); var json = jsonWriter.ToString(); return json; } }
private void WriteJsonModel(JsonModel model) { model.ToJsonInternal(this, _writer); }