public string setCBCCtoPHP(string url, string postData) { string webpageContent = string.Empty; try { String deviceToken = HttpUtility.UrlEncode("5E66BF7E-3642-4B5B-80C1-6BFB73698A96"); postData = String.Format("deviceToken={0}&data={1}", deviceToken, getCBCC()); byte[] byteArray = Encoding.UTF8.GetBytes(postData); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = byteArray.Length; // Gửi dữ liệu using (Stream webpageStream = webRequest.GetRequestStream()) { webpageStream.Write(byteArray, 0, byteArray.Length); } // Lấy kết quả trả về using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) { using (StreamReader reader = new StreamReader(webResponse.GetResponseStream())) { webpageContent = reader.ReadToEnd(); } } } catch (Exception ex) { //throw or return an appropriate response/exception } return(JSonHelper.ToJson(webpageContent)); }
//save the data from JSON file public void SaveGameData() { string dataAsJson = JSonHelper.ToJson(teamData, true); string filePath = Application.persistentDataPath + gameDataProjectFilePath; File.WriteAllText(filePath, dataAsJson); uncheckedData = true; }
public string getCBCC() { try { return(JSonHelper.ToJson(SqlHelper.ExecuteDataset( SiteMaster._vConnectString, CommandType.Text, "SELECT DoiTuongID, TenDoiTuong, Tuoi FROM dbo.tblDMDoiTuong", null ).Tables[0])); } catch (Exception ex) { return(JSonHelper.ToJson(new DataTable())); } }
public void ExportChanges() { JsonData[] finalJson = new JsonData[changelog.Count]; finalJson.Initialize(); int counter = 0; foreach (KeyValuePair <int, JsonData> item in changelog) { finalJson[counter] = item.Value; counter++; } string toJson = JSonHelper.ToJson <JsonData>(finalJson); string path = Application.dataPath + "/exportData.txt"; System.IO.File.WriteAllText(Application.dataPath + "/exportData.txt", toJson); }
public string getCBCCfromPHP(object data) { try { string siteContent = string.Empty; string url = data.ToString(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // Tạo yêu cầu request.AutomaticDecompression = DecompressionMethods.GZip; // Loại nén dữ liệu using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) // Gửi đến query php using (Stream responseStream = response.GetResponseStream()) // Lấy dữ liệu trả về từ php using (StreamReader streamReader = new StreamReader(responseStream)) // Đọc dữ liệu { siteContent = streamReader.ReadToEnd(); // Ghi dữ liệu } DataSet ds = (DataSet)JsonConvert.DeserializeObject(siteContent, (typeof(DataSet))); DataTable dt = ds.Tables[0]; int success = 0; string sql = string.Empty; foreach (DataRow item in dt.Rows) { sql = string.Empty; sql = @"INSERT INTO dbo.tblDMDoiTuong ( DoiTuongID, TenDoiTuong, Tuoi ) OUTPUT inserted.* VALUES (N'" + item["DoiTuongID"].ToString() + @"',N'" + item["TenDoiTuong"].ToString() + @"',N'" + item["Tuoi"].ToString() + @"')"; try { DataSet ds1 = SqlHelper.ExecuteDataset(SiteMaster._vConnectString, CommandType.Text, sql, null); if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0) { success++; } } catch (Exception ex) { } } return(JSonHelper.ToJson("Thêm thành công: " + success + "<br>" + "Thêm không thành công: " + (dt.Rows.Count - success))); } catch (Exception ex) { return(JSonHelper.ToJson(ex.ToString())); } }