// JSONフォーマットの文字列から匿名型データを作る private void LoadData(string json) { // JSONフォーマットの文字列からJsonObjectオブジェクトを作る var data = new Windows.Data.Json.JsonObject(); bool success = Windows.Data.Json.JsonObject.TryParse(json, out data); if (success) { // JsonObjectオブジェクトから画面表示に必要なデータを取り出し、 // 匿名型のオブジェクトに詰め込む Windows.Data.Json.JsonObject weather = data.GetNamedArray("weather", null)?.GetObjectAt(0); Windows.Data.Json.JsonObject main = data.GetNamedObject("main", null); string iconId = weather?.GetNamedString("icon", string.Empty); Data = new { Main = weather?.GetNamedString("main", "(不明)"), Temp = main?.GetNamedNumber("temp", -999), TempMin = main?.GetNamedNumber("temp_min", -999), TempMax = main?.GetNamedNumber("temp_max", -999), Place = data.GetNamedString("name", "(不明)"), IconUrl = iconId != null ? $"http://openweathermap.org/img/w/{iconId}.png" : null, }; } }
public async void GetWeather(string text) { Windows.Data.Json.JsonObject total_json = await service.GetWeatherItem(text); if (total_json == null) { MessageDialog dialog = new MessageDialog("搜索不到相关城市信息\n请检查输入是否无误"); await dialog.ShowAsync(); return; } StringBuilder message = new StringBuilder(""); if (total_json.GetNamedNumber("showapi_res_code") != 0) { message.AppendLine(total_json.GetNamedString("showapi_res_error")); MessageDialog dialog = new MessageDialog(message.ToString()); await dialog.ShowAsync(); } else { json = total_json.GetNamedObject("showapi_res_body"); current_item.Area = json.GetNamedObject("cityInfo").GetNamedString("c9") + json.GetNamedObject("cityInfo").GetNamedString("c7") + "省" + json.GetNamedObject("cityInfo").GetNamedString("c3") + "市"; current_item.Json = json.GetNamedObject("now"); AllItems.Clear(); for (int i = 1; i <= 7; i++) { AllItems.Add(new WeatherItem(json.GetNamedObject("f" + i))); } } }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.Id = (int)jsonObj["Id"].GetNumber(); this.Firm = jsonObj["Firm"].GetString(); this.Account = jsonObj["Account"].GetString(); this.Class = jsonObj["Class"].GetString(); this.Client = jsonObj["Client"].GetString(); }
public WeatherItem(Windows.Data.Json.JsonObject json) { Day = json.GetNamedString("day"); weekday = (int)json.GetNamedNumber("weekday"); day_air_temperature = json.GetNamedString("day_air_temperature"); night_air_temperature = json.GetNamedString("night_air_temperature"); Weather = json.GetNamedString("day_weather"); Weather_pic = json.GetNamedString("day_weather_pic"); }
public Windows.Data.Json.JsonObject GetJsonObj() { var obj = new Windows.Data.Json.JsonObject(); obj.Add("name", Windows.Data.Json.JsonValue.CreateStringValue(name)); obj.Add("num", Windows.Data.Json.JsonValue.CreateStringValue(num)); obj.Add("com", Windows.Data.Json.JsonValue.CreateStringValue(com)); obj.Add("color", Windows.Data.Json.JsonValue.CreateStringValue(color.A + "," + color.R + "," + color.G + "," + color.B)); return(obj); }
public static void ClassSetup(TestContext context) { context?.WriteLine("Started loading test setup"); Windows.Data.Json.JsonObject file = GetJSONFile("/Assets/testdata.json"); foreach (Windows.Data.Json.IJsonValue element in file["strings"].GetArray()) { Items.Add(new FilterableString(element.GetString())); } context?.WriteLine("Finished test setup"); }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.MarketData = new MarketData(); this.SecurityInfo = new SecurityInfo(); var md = jsonObj["MarketData"].GetObject(); var si = jsonObj["SecurityInfo"].GetObject(); this.MarketData.LCURRENTPRICE = (decimal)md["LCURRENTPRICE"].GetNumber(); this.MarketData.OPENPERIODPRICE = (decimal)md["OPENPERIODPRICE"].GetNumber(); this.SecurityInfo.PREVLEGALCLOSEPRICE = (decimal)si["PREVLEGALCLOSEPRICE"].GetNumber(); }
public static async Task Add(KD_Model kd) { var ColorList = new List <Windows.UI.Color>(); ColorList.Add(Windows.UI.Color.FromArgb(255, 238, 88, 88)); ColorList.Add(Windows.UI.Color.FromArgb(255, 231, 238, 88)); ColorList.Add(Windows.UI.Color.FromArgb(255, 163, 238, 88)); ColorList.Add(Windows.UI.Color.FromArgb(255, 108, 238, 88)); ColorList.Add(Windows.UI.Color.FromArgb(255, 88, 238, 108)); ColorList.Add(Windows.UI.Color.FromArgb(255, 88, 238, 170)); ColorList.Add(Windows.UI.Color.FromArgb(255, 88, 238, 101)); ColorList.Add(Windows.UI.Color.FromArgb(255, 88, 238, 0)); ColorList.Add(Windows.UI.Color.FromArgb(255, 226, 23, 60)); ColorList.Add(Windows.UI.Color.FromArgb(255, 79, 168, 147)); int num = new Random().Next(0, ColorList.Count); kd.color = ColorList[num]; var kd_file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("kd_file", Windows.Storage.CreationCollisionOption.OpenIfExists); var tempkdfile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("tempkdfile", Windows.Storage.CreationCollisionOption.OpenIfExists); var temparray = new Windows.Data.Json.JsonArray(); if (await Windows.Storage.FileIO.ReadTextAsync(tempkdfile) != "") { temparray = Windows.Data.Json.JsonArray.Parse(await Windows.Storage.FileIO.ReadTextAsync(tempkdfile)); } var tempobj = new Windows.Data.Json.JsonObject(); tempobj.Add("num", Windows.Data.Json.JsonValue.CreateStringValue(kd.num)); tempobj.Add("time", Windows.Data.Json.JsonValue.CreateStringValue("0")); temparray.Add(tempobj); await Windows.Storage.FileIO.WriteTextAsync(tempkdfile, temparray.ToString()); var json = await Windows.Storage.FileIO.ReadTextAsync(kd_file); if (json != "") { var array = Windows.Data.Json.JsonArray.Parse(json); array.Add(kd.GetJsonObj()); json = array.ToString(); } else { var obj = new Windows.Data.Json.JsonArray(); obj.Add(kd.GetJsonObj()); json = obj.ToString(); } await Windows.Storage.FileIO.WriteTextAsync(kd_file, json); }
private async void SaveKuaiDiData(object sender, RoutedEventArgs e) { if (kd_name.Text != "" && kd_num.Text != "" && KuaiDicombox.SelectedIndex > 0) { var obj = new Windows.Data.Json.JsonObject(); obj.Add("name", Windows.Data.Json.JsonValue.CreateStringValue(kd_name.Text)); obj.Add("num", Windows.Data.Json.JsonValue.CreateStringValue(kd_num.Text)); obj.Add("com", Windows.Data.Json.JsonValue.CreateStringValue(comDir.Values.ToArray()[KuaiDicombox.SelectedIndex])); localData.Values["KuaiDiData"] = obj.ToString(); await new Windows.UI.Popups.MessageDialog("已保存").ShowAsync(); } else { await new Windows.UI.Popups.MessageDialog("请输入快递信息").ShowAsync(); } }
public DataLayer.ImgurUser jsonToUser(Windows.Data.Json.JsonObject json) { DataLayer.ImgurUser _usr; //---------------------------- _usr = new DataLayer.ImgurUser(); _usr.Id = (int)(json.GetNamedArray("data").GetNumberAt(0)); _usr.Url = json.GetNamedArray("data").GetStringAt(1); _usr.Bio = json.GetNamedArray("data").GetStringAt(2); _usr.Rep = (float)json.GetNamedArray("data").GetNumberAt(3); _usr.Created = (int)json.GetNamedArray("data").GetNumberAt(4); _usr.Pro = (int)json.GetNamedArray("data").GetNumberAt(5); // return user return(_usr); }
public int ReadValue(Windows.Data.Json.JsonObject jsonObj, string field) { int value = 0; var fieldType = jsonObj[field].ValueType; if (fieldType == Windows.Data.Json.JsonValueType.Number) { value = (int)jsonObj[field].GetNumber(); } if (fieldType == Windows.Data.Json.JsonValueType.String) { value = int.Parse(jsonObj[field].GetString(), System.Globalization.CultureInfo.InvariantCulture); } return(value); }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.Id = (int)jsonObj["Id"].GetNumber(); this.Year = (int)jsonObj["Year"].GetNumber(); this.Period = (int)jsonObj["Period"].GetNumber(); this.Revenue = (decimal)jsonObj["Revenue"].GetNumber(); this.OperatingExpenses = (decimal)jsonObj["OperatingExpenses"].GetNumber(); this.OperatingIncome = (decimal)jsonObj["OperatingIncome"].GetNumber(); this.NetIncome = (decimal)jsonObj["NetIncome"].GetNumber(); this.CurrentAssets = (decimal)jsonObj["CurrentAssets"].GetNumber(); this.FixedAssets = (decimal)jsonObj["FixedAssets"].GetNumber(); this.TotalAssets = (decimal)jsonObj["TotalAssets"].GetNumber(); this.CurrentLiabilities = (decimal)jsonObj["CurrentLiabilities"].GetNumber(); this.LongTermLiabilities = (decimal)jsonObj["LongTermLiabilities"].GetNumber(); this.TotalLiabilities = (decimal)jsonObj["TotalLiabilities"].GetNumber(); this.Equity = (decimal)jsonObj["Equity"].GetNumber(); this.LiabilitiesAndEquity = (decimal)jsonObj["LiabilitiesAndEquity"].GetNumber(); this.FlowOperatingActivities = (decimal)jsonObj["FlowOperatingActivities"].GetNumber(); this.ChangesInAssets = (decimal)jsonObj["ChangesInAssets"].GetNumber(); this.Amortization = (decimal)jsonObj["Amortization"].GetNumber(); this.Capex = (decimal)jsonObj["Capex"].GetNumber(); this.FlowOperatingTaxesPaid = (decimal)jsonObj["FlowOperatingTaxesPaid"].GetNumber(); this.FlowInvestingActivities = (decimal)jsonObj["FlowInvestingActivities"].GetNumber(); this.FlowFinancingActivities = (decimal)jsonObj["FlowFinancingActivities"].GetNumber(); this.StockIssuance = (decimal)jsonObj["StockIssuance"].GetNumber(); this.DividendsPaid = (decimal)jsonObj["DividendsPaid"].GetNumber(); this.EarningsPerShare = (decimal)jsonObj["EarningsPerShare"].GetNumber(); this.Price = (decimal)jsonObj["Price"].GetNumber(); this.EBITDA = (decimal)jsonObj["EBITDA"].GetNumber(); this.FCF = (decimal)jsonObj["FCF"].GetNumber(); this.PriceEarningsRatio = (decimal)jsonObj["PriceEarningsRatio"].GetNumber(); this.ReturnOnEquity = (decimal)jsonObj["ReturnOnEquity"].GetNumber(); }
public static void RefreshToken(Action <ResultCode> callback) { Dictionary <string, string> parameters2 = new Dictionary <string, string>(); parameters2["receipt"] = "";// "fNVR-A-6qDY:APA91bH83Yy6pNAQw9Dqdo_uhyscoBSv9jmzvYA6pke0U1VaukpzGO0kCvJrVoIMlyD3pH492U39GPRBYKCpeugrdbcBfKHhU88PG5tXM0mVBTS7sTPVgA9ymbEkuMdwlC6-6oxxgtzJ"; //X-appid fNVR-A-6qDY //receipt fNVR-A-6qDY:APA91bG8gx5e5vSMierSHiZbxivavml4UJkU2-TmDSExmnDitbZibh4oo7M8I27YG6vS0Pv1LLjAJDpWqaj4xVY-eKMj8ggdSSjC_Rx2VSnDhOuNorjvAkPoOUt_8JzsO6OvSB6lc_VW //token fNVR-A-6qDY:APA91bG8gx5e5vSMierSHiZbxivavml4UJkU2-TmDSExmnDitbZibh4oo7M8I27YG6vS0Pv1LLjAJDpWqaj4xVY-eKMj8ggdSSjC_Rx2VSnDhOuNorjvAkPoOUt_8JzsO6OvSB6lc_VW VKRequestsDispatcher.DispatchRequestToVK <AutorizationData>("auth.refreshToken", parameters2, (Action <BackendResult <AutorizationData, ResultCode> >)(result => { VKRequestsDispatcher._autorizationData.access_token = result.ResultData.access_token; callback(result.ResultCode); }), new Func <string, AutorizationData>((s) => { s = s.Replace("token", "access_token"); Windows.Data.Json.JsonObject jsonObject = Windows.Data.Json.JsonObject.Parse(s); Windows.Data.Json.JsonObject a = jsonObject["response"].GetObject(); string temp = a.ToString(); AutorizationData aa = JsonConvert.DeserializeObject <AutorizationData>(temp); return(aa); })); }
private void replacePatient(IUICommand command) { Windows.Data.Json.JsonObject updatedPatient = new Windows.Data.Json.JsonObject(); string patString = command.Id.ToString(); updatedPatient = Windows.Data.Json.JsonObject.Parse(patString); for (uint i = 0; i < patients.Count; i++) { if (updatedPatient["Name"].GetString() == patients.GetObjectAt(i).GetNamedValue("Name").GetString() && updatedPatient["Birthday"].GetString() == patients.GetObjectAt(i).GetNamedValue("Birthday").GetString()) { patients.GetObjectAt(i).SetNamedValue("Education", updatedPatient["Education"]); patients.GetObjectAt(i).SetNamedValue("Sex", updatedPatient["Sex"]); } } }
async void saveUserData() { try { //get file Windows.Storage.StorageFile myFile = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(filename); //read //String data = await Windows.Storage.FileIO.ReadTextAsync(myFile); //save //string allUserDataString = name + ", " + birthday + ", " + age + ", " + sex + ", " + educationLevel; Windows.Data.Json.JsonObject newPatient = new Windows.Data.Json.JsonObject(); newPatient["Doctor"] = Windows.Data.Json.JsonValue.CreateStringValue(docName); newPatient["Name"] = Windows.Data.Json.JsonValue.CreateStringValue(name); newPatient["Birthday"] = Windows.Data.Json.JsonValue.CreateStringValue(birthday.ToString()); newPatient["Age"] = Windows.Data.Json.JsonValue.CreateNumberValue(age); newPatient["Sex"] = Windows.Data.Json.JsonValue.CreateStringValue(sex.ToString()); newPatient["Education"] = Windows.Data.Json.JsonValue.CreateStringValue(educationLevel); //check if user is already saved bool addNew = true; for (uint i=0; i < patients.Count; i++){ if (patients.GetObjectAt(i).GetNamedValue("Name").GetString() == newPatient["Name"].GetString() && patients.GetObjectAt(i).GetNamedValue("Birthday").GetString() == newPatient["Birthday"].GetString()) { //patient info already saved // Create the message dialog and set its content var messageDialog = new MessageDialog("We already have a patient with that name and birthday. Do you want to replace the existing patient?"); // Add commands and set their callbacks string jsonPatient = newPatient.Stringify(); messageDialog.Commands.Add(new UICommand("Replace Old Patient", new UICommandInvokedHandler(this.replacePatient), jsonPatient)); messageDialog.Commands.Add(new UICommand("Keep Original Patient", new UICommandInvokedHandler(this.doNothing))); // Set the command that will be invoked by default messageDialog.DefaultCommandIndex = 0; // Set the command to be invoked when escape is pressed messageDialog.CancelCommandIndex = 1; // Show the message dialog await messageDialog.ShowAsync(); addNew = false; } } if(addNew) { patients.Add(newPatient); } string jsonAllPatientsString = patients.Stringify(); await Windows.Storage.FileIO.WriteTextAsync(myFile, jsonAllPatientsString); //await Windows.Storage.FileIO.WriteTextAsync(myFile, ""); //uncomment this to erase database } catch (FileNotFoundException) { //file did not exist so create it - SHOULD NEVER HAPPEN because of "openIfExists" Popup p = new Popup(); TextBlock t = new TextBlock(); t.Text = "Error: file could not be opened"; p.Child = t; create_file(); } }
public virtual void ReadData(Windows.Data.Json.JsonObject jsonObj) { }
public override void ReadData(Windows.Data.Json.JsonObject jsonObj) { this.Id = (int)jsonObj["Id"].GetNumber(); this.Date = DateTime.Parse(jsonObj["Date"].GetString()); }
/// <summary> /// json 解析无指定正确的类型 /// </summary> /// <param name="obj">数据</param> /// <returns></returns> public Windows.Data.Json.JsonObject DeSerializationJson(String obj) { Windows.Data.Json.JsonObject ob = null; Windows.Data.Json.JsonObject.TryParse(obj, out ob); return(ob); }
public CurrentWeatherItem(Windows.Data.Json.JsonObject jo = null) { json = jo; }