/// <summary> /// Creates a new anonymous stomt on the specified target with an image attached to it. /// </summary> /// <param name="positive">The stomt type. True for "I like" and false for "I wish".</param> /// <param name="target">The target to post the stomt to.</param> /// <param name="text">The stomt message.</param> /// <param name="image">The image texture to upload and attach to the stomt.</param> public void CreateStomtWithImage(bool positive, string target, string text, Texture2D image) { if (image == null) { CreateStomt(positive, target, text); return; } byte[] imageBytes = image.EncodeToPNG(); if (imageBytes == null) { return; } var jsonImage = new StringBuilder(); var writerImage = new LitJson.JsonWriter(jsonImage); writerImage.WriteObjectStart(); writerImage.WritePropertyName("images"); writerImage.WriteObjectStart(); writerImage.WritePropertyName("stomt"); writerImage.WriteArrayStart(); writerImage.WriteObjectStart(); writerImage.WritePropertyName("data"); writerImage.Write(Convert.ToBase64String(imageBytes)); writerImage.WriteObjectEnd(); writerImage.WriteArrayEnd(); writerImage.WriteObjectEnd(); writerImage.WriteObjectEnd(); var jsonStomt = new StringBuilder(); var writerStomt = new LitJson.JsonWriter(jsonStomt); writerStomt.WriteObjectStart(); writerStomt.WritePropertyName("anonym"); writerStomt.Write(true); writerStomt.WritePropertyName("positive"); writerStomt.Write(positive); writerStomt.WritePropertyName("target_id"); writerStomt.Write(target); writerStomt.WritePropertyName("text"); writerStomt.Write(text); writerStomt.WritePropertyName("img_name"); writerStomt.Write("{img_name}"); writerStomt.WriteObjectEnd(); StartCoroutine(CreateStomtWithImageAsync(jsonImage.ToString(), jsonStomt.ToString())); }
public static void ToJson(ISerializable val, LitJson.JsonWriter writer) { writer.WriteObjectStart(); var s = new Serializer(writer); val.ToJson(s); writer.WriteObjectEnd(); }
static void JsonExportPointF(PointF pt, LitJson.JsonWriter writer) { writer.WriteObjectStart(); writer.WritePropertyName("X"); writer.Write(pt.X); writer.WritePropertyName("Y"); writer.Write(pt.Y); writer.WriteObjectEnd(); }
public static void ToJson(IDictionary <string, LitJson.JsonData> val, LitJson.JsonWriter writer) { writer.WriteObjectStart(); foreach (var pair in val) { writer.WritePropertyName(pair.Key); ToJson(pair.Value, writer); } writer.WriteObjectEnd(); }
public static void ToJson <T>(IDictionary <string, T> val, LitJson.JsonWriter writer) where T : ISerializable { writer.WriteObjectStart(); foreach (var pair in val) { writer.WritePropertyName(pair.Key); ToJson(pair.Value, writer); } writer.WriteObjectEnd(); }
/// <summary> /// Creates a new anonymous stomt on the specified target. /// </summary> /// <param name="positive">The stomt type. True for "I like" and false for "I wish".</param> /// <param name="target">The target to post the stomt to.</param> /// <param name="text">The stomt message.</param> public void CreateStomt(bool positive, string target, string text) { var json = new StringBuilder(); var writer = new LitJson.JsonWriter(json); writer.WriteObjectStart(); writer.WritePropertyName("anonym"); writer.Write(true); writer.WritePropertyName("positive"); writer.Write(positive); writer.WritePropertyName("target_id"); writer.Write(target); writer.WritePropertyName("text"); writer.Write(text); writer.WriteObjectEnd(); StartCoroutine(CreateStomtAsync(json.ToString())); }
public void InitiliazeConfig(string path) { var filePath = $"{path}\\PicPrompt.json"; if (!File.Exists(filePath)) { var writer = new LitJson.JsonWriter(); writer.WriteObjectStart(); writer.WritePropertyName("start-with-windows-enabled"); writer.Write(false); writer.WritePropertyName("allow-background-work"); writer.Write(true); writer.WriteObjectEnd(); File.WriteAllText(filePath, writer.ToString()); } Config.Load(filePath); }
static int _m_WriteObjectEnd(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.WriteObjectEnd( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public static void CustomSerialization(Dictionary <string, object> dict, LitJson.JsonWriter jsonWriter) { jsonWriter.WriteObjectStart(); foreach (var dictKey in dict.Keys) { var val = dict[dictKey]; if (_customTypes.Contains(val.GetType())) { // 可以写入的类型 jsonWriter.WritePropertyName(dictKey); WriteValue(jsonWriter, val); } else if (val is Dictionary <string, object> subDic) { jsonWriter.WritePropertyName(dictKey); CustomSerialization(subDic, jsonWriter); } } jsonWriter.WriteObjectEnd(); }