public static string ToJson(object obj) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0, true); return(static_writer.ToString()); } }
public static string ToPrettyJson(object obj) { lock (static_writer_lock) { static_writer.Reset(); static_writer.PrettyPrint = true; WriteValue(obj, static_writer, true, 0); static_writer.PrettyPrint = false; return(static_writer.ToString()); } }
public static string ToJson(object obj, bool withTypeInfo = false) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0, withTypeInfo); return(static_writer.ToString()); } }
public static string ToJson(object obj, bool format = false) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); return(format ? JsonFromat.FormatJson(static_writer.ToString()) : static_writer.ToString()); } }
public static string ToJson(object obj, bool hex = true, bool pretty = false) { lock (static_writer_lock) { static_writer.Reset(); static_writer.PrettyPrint = pretty; WriteValue(obj, static_writer, true, 0, hex); return(static_writer.ToString()); } }
public static string ToJson(object obj, bool ignoreField = false) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0, ignoreField); return(static_writer.ToString()); } }
public static string ToJson(object obj, bool isEncode = true) { lock (static_writer_lock) { static_writer.Reset(); static_writer.IsEncode = isEncode; WriteValue(obj, static_writer, true, 0); return(static_writer.ToString()); } }
public static string ToJson(object obj) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); var json = static_writer.ToString(); //解决中文为正则表达式的问题 //json = System.Text.RegularExpressions.Regex.Unescape(json); return(json); } }
public static string ToJson(object obj) { //JsonMapper.RegisterExporter<float>((obj, writer) => writer.Write(Convert.ToDouble(obj))); // JsonMapper.RegisterImporter<double, float>(input => Convert.ToSingle(input)); lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); return(static_writer.ToString()); } }
/// <summary> /// 输出符合文本可视化的Json /// </summary> /// <param name="obj"></param> public static string ToPrettyJson(object obj) { lock (_prettyJsonWriter) { _prettyJsonWriter.Reset(); if (false == _prettyJsonWriter.PrettyPrint) { _prettyJsonWriter.IndentValue = 4; _prettyJsonWriter.PrettyPrint = true; } WriteValue(obj, _prettyJsonWriter, true, 0); return(_prettyJsonWriter.ToString()); } }
public static string ToJson(object obj) { if (obj == null) { return(string.Empty); } lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); return(static_writer.ToString()); } }
public static string ToJson(object obj, bool shouldCompress = false) { lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); if (shouldCompress) { string jsonStr = static_writer.ToString(); return(jsonStr); } return(static_writer.ToString()); } }
/// <summary> /// 输出符合文本可视化的Json /// </summary> /// <param name="obj"></param> public static string ToPrettyJson(object obj) { lock (_prettyJsonWriter) { _prettyJsonWriter.Reset(); if (false == _prettyJsonWriter.PrettyPrint) { _prettyJsonWriter.IndentValue = 4; _prettyJsonWriter.PrettyPrint = true; } WriteValue(obj, _prettyJsonWriter, true, 0); var json = _prettyJsonWriter.ToString(); //解决中文为正则表达式的问题 json = System.Text.RegularExpressions.Regex.Unescape(json); return(json); } }
void _TestSerialInfo() { SerialInfo v1 = new SerialInfo(); v1.vector2 = new Vector2(0.5f, 0.5f); if (m_Format == Format.Pretty) { m_PrettyWriter.Reset(); LitJson.JsonMapper.ToJson(v1, m_PrettyWriter); m_str1 = m_PrettyWriter.ToString(); } else { m_str1 = LitJson.JsonMapper.ToJson(v1); //serialize object to string } LitJson.JsonMapper.ToObject <SerialInfo>(m_str1); //de-serialize string back to object }
public static string ToJson(object obj, bool isformat = false) { if (isformat) { var jw = new JsonWriter() { IndentValue = 2, PrettyPrint = true }; ToJson(obj, jw); return(jw.ToString()); } lock (static_writer_lock) { static_writer.Reset(); WriteValue(obj, static_writer, true, 0); return(static_writer.ToString()); } }
public void ExportPrettyPrint() { OrderedDictionary sample = new OrderedDictionary (); sample["rolling"] = "stones"; sample["flaming"] = "pie"; sample["nine"] = 9; string expected = @" { ""rolling"" : ""stones"", ""flaming"" : ""pie"", ""nine"" : 9 }"; JsonWriter writer = new JsonWriter (); writer.PrettyPrint = true; JsonMapper.ToJson (sample, writer); Assert.AreEqual (expected, writer.ToString (), "A1"); writer.Reset (); writer.IndentValue = 8; expected = @" { ""rolling"" : ""stones"", ""flaming"" : ""pie"", ""nine"" : 9 }"; JsonMapper.ToJson (sample, writer); Assert.AreEqual (expected, writer.ToString (), "A2"); }
private void ProcessData() { var received = m_wpos - m_rpos; while (received >= Packet.headerSize) { if (destroyed || !m_socket.Connected) { return; // if the session is disconnected or receiver destroyed, stop processing data immdiately } var mask = ByteConverter.ToUInt32(m_buffer, m_rpos); // low 24 bit = length, hight 8 bit = bitmask var length = (int)((mask & 0xFFFFFF) + 4); // server side packet length does not contain mask length //var bimask = mask >> 24; if (length < Packet.headerSize) // got invalid packet data, stop processing data immdiately and disconnect from server { Logger.LogException("PacketReceiver got invalid packet data header, header length is {0} but required {1}", length, Packet.headerSize); Close(); return; } if (received >= length) { var id = ByteConverter.ToUInt16(m_buffer, m_rpos + 4); var header = id | (long)length << 16; var bytes = new byte[length]; Array.Copy(m_buffer, m_rpos, bytes, 0, length); m_rpos += length; received -= length; PacketObject o; lock (m_guard_packet) { m_packet.Set(header, bytes); o = PacketObject.Create(m_packet); #if DEVELOPMENT_BUILD || UNITY_EDITOR if (o != null) { var f = ConfigManager.Get <ProtocolLoggerFilter>(o._ID); if (!f || !f.disabled) { if (!f || !f.noDetail) { m_jsonWriter.Reset(); try { LitJson.JsonMapper.ToJson(o, m_jsonWriter, 5); Logger.Log(LogType.RECV, "Recv: [{0}:{1}-{2},{3}] {4}", m_packet.ID, m_packet.dataSize, Level.realTime, o._name, m_jsonWriter); } catch (Exception ee) { m_jsonWriter = new LitJson.JsonWriter() { CsFormat = true, PrettyPrint = true }; Logger.Log(LogType.RECV, "Recv: [{0}:{1}-{2},{3}]", m_packet.ID, m_packet.dataSize, Level.realTime, o._name); Logger.LogException(ee); } } else { Logger.Log(LogType.RECV, "Recv: [{0}:{1}-{2},{3}]", m_packet.ID, m_packet.dataSize, Level.realTime, o._name); } if (f && f.cpp) { o.LogCppString(m_sb); } } } else { Logger.LogError("Receive unknow packet: [{0}:{1}-{2}], packet not registered.", m_packet.ID, m_packet.dataSize, Level.realTime); } #endif m_packet.Reset(); } if (o != null) { lock (m_guard_write) { m_front.Add(o); } } } else { break; } } }