private void SendFile(string fileContent, Action <LitJsonStomt.JsonData> callbackSuccess, Action <HttpWebResponse> callbackError, Action callbackOffline) { // Convert to Base64 var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(fileContent); var file = System.Convert.ToBase64String(plainTextBytes); // Build Body var jsonFileUpload = new StringBuilder(); var writerImage = new LitJsonStomt.JsonWriter(jsonFileUpload); writerImage.WriteObjectStart(); writerImage.WritePropertyName("files"); writerImage.WriteObjectStart(); writerImage.WritePropertyName("stomt"); writerImage.WriteArrayStart(); writerImage.WriteObjectStart(); writerImage.WritePropertyName("data"); writerImage.Write(file); writerImage.WritePropertyName("filename"); writerImage.Write("UnityLogs"); writerImage.WriteObjectEnd(); writerImage.WriteArrayEnd(); writerImage.WriteObjectEnd(); writerImage.WriteObjectEnd(); // Send Request var url = string.Format("{0}/files", restServerURL); GetPOSTResponse(url, jsonFileUpload.ToString(), callbackSuccess, callbackError, callbackOffline); }
private void SendImage(string image, Action <LitJsonStomt.JsonData> callbackSuccess, Action <HttpWebResponse> callbackError, Action callbackOffline) { // Build Body var jsonImage = new StringBuilder(); var writerImage = new LitJsonStomt.JsonWriter(jsonImage); writerImage.WriteObjectStart(); writerImage.WritePropertyName("images"); writerImage.WriteObjectStart(); writerImage.WritePropertyName("stomt"); writerImage.WriteArrayStart(); writerImage.WriteObjectStart(); writerImage.WritePropertyName("data"); writerImage.Write(image); writerImage.WriteObjectEnd(); writerImage.WriteArrayEnd(); writerImage.WriteObjectEnd(); writerImage.WriteObjectEnd(); // Send Request var url = string.Format("{0}/images", restServerURL); GetPOSTResponse(url, jsonImage.ToString(), callbackSuccess, callbackError, callbackOffline); }
public override string ToString() { var jsonStomt = new StringBuilder(); var writerStomt = new LitJsonStomt.JsonWriter(jsonStomt); writerStomt.WriteObjectStart(); //writerStomt.WritePropertyName("anonym"); //writerStomt.Write(this.anonym); writerStomt.WritePropertyName("positive"); writerStomt.Write(this.positive); writerStomt.WritePropertyName("text"); writerStomt.Write(this.text); writerStomt.WritePropertyName("lang"); writerStomt.Write(this.lang); if (!string.IsNullOrEmpty(this.target_id)) { writerStomt.WritePropertyName("target_id"); writerStomt.Write(this.target_id); } // Add labels writerStomt.WritePropertyName("extradata"); writerStomt.WriteObjectStart(); writerStomt.WritePropertyName("labels"); writerStomt.WriteArrayStart(); if (labels.Length > 0) { foreach (string label in labels) { if (label != "AddLabelHere" && label != "add-label-here") { writerStomt.Write(label); } } } // Add default labels if (!DisableDefaultLabels) { writerStomt.Write(Application.platform.ToString()); writerStomt.Write(Screen.currentResolution.ToString()); } writerStomt.WriteArrayEnd(); // Add CustomKeyValuePairs if (CustomKeyValuePairs.Count > 0) { foreach (List <string> PairList in CustomKeyValuePairs) { if (PairList.Count > 1) { writerStomt.WritePropertyName(PairList[0]); writerStomt.Write(PairList[1]); } } } writerStomt.WriteObjectEnd(); if (!string.IsNullOrEmpty(this.img_name)) { writerStomt.WritePropertyName("img_name"); writerStomt.Write(this.img_name); } if (!string.IsNullOrEmpty(this.file_uid)) { writerStomt.WritePropertyName("files"); writerStomt.WriteObjectStart(); writerStomt.WritePropertyName("stomt"); writerStomt.WriteObjectStart(); writerStomt.WritePropertyName("file_uid"); writerStomt.Write(this.file_uid); writerStomt.WriteObjectEnd(); writerStomt.WriteObjectEnd(); } writerStomt.WriteObjectEnd(); return(jsonStomt.ToString()); }
private static void WriteJson(IJsonWrapper obj, JsonWriter writer) { if (obj == null) { writer.Write(null); return; } if (obj.IsString) { writer.Write(obj.GetString()); return; } if (obj.IsBoolean) { writer.Write(obj.GetBoolean()); return; } if (obj.IsDouble) { writer.Write(obj.GetDouble()); return; } if (obj.IsInt) { writer.Write(obj.GetInt()); return; } if (obj.IsLong) { writer.Write(obj.GetLong()); return; } if (obj.IsArray) { writer.WriteArrayStart(); foreach (object elem in (IList)obj) { WriteJson((JsonData)elem, writer); } writer.WriteArrayEnd(); return; } if (obj.IsObject) { writer.WriteObjectStart(); foreach (DictionaryEntry entry in ((IDictionary)obj)) { writer.WritePropertyName((string)entry.Key); WriteJson((JsonData)entry.Value, writer); } writer.WriteObjectEnd(); return; } }