public JsonObject toJson() { JsonObject retval = new JsonObject(); // create the JsonArrays we will be outputting JsonArray sNodeSparqlIdArray = new JsonArray(); JsonArray sNodeOptionalArray = new JsonArray(); JsonArray sNodeDeletionArray = new JsonArray(); for (int p = 0; p < this.nodes.Count; p++) { // build the array as needed. sNodeSparqlIdArray.Add(JsonValue.CreateStringValue(this.nodes[p].GetSparqlID())); sNodeOptionalArray.Add(JsonValue.CreateNumberValue(this.snodeOptionals[p])); sNodeDeletionArray.Add(JsonValue.CreateBooleanValue(this.deletionFlags[p])); } // add all the tags we need... retval.Add("SnodeSparqlIDs", sNodeSparqlIdArray); retval.Add("SnodeOptionals", sNodeOptionalArray); retval.Add("DeletionMarkers", sNodeDeletionArray); retval.Add("KeyName", JsonValue.CreateStringValue(this.keyName)); retval.Add("ValueType", JsonValue.CreateStringValue(this.valueType)); retval.Add("UriValueType", JsonValue.CreateStringValue(this.valueTypeURI)); retval.Add("ConnectBy", JsonValue.CreateStringValue(this.connectedBy)); retval.Add("Connected", JsonValue.CreateBooleanValue(this.connected)); retval.Add("UriConnectBy", JsonValue.CreateStringValue(this.uriConnectBy)); return(retval); }
private void SendCommandButton_Click(object sender, RoutedEventArgs e) { if (ModeComboBox.SelectedItem == null) { ModeComboBox.SelectedItem = "Auto"; } if (FanSpeedComboBox.SelectedItem == null) { FanSpeedComboBox.SelectedItem = "Auto"; } JsonObject commandData = new JsonObject { ["power"] = JsonValue.CreateBooleanValue(PowerToggleSwitch.IsOn), ["fanSpeed"] = JsonValue.CreateStringValue(FanSpeedComboBox.SelectedItem.ToString().ToLower()), ["Mode"] = JsonValue.CreateStringValue(ModeComboBox.SelectedItem.ToString().ToLower()), ["temp"] = JsonValue.CreateNumberValue(Convert.ToInt32(TempSlider.Value)) }; JsonObject sendData = new JsonObject { ["protocol"] = JsonValue.CreateStringValue("myEspNet"), ["command"] = JsonValue.CreateStringValue("set"), ["data"] = commandData }; LogTextBox.Text += sendData.ToString() + "\r\n"; BroadCastUdpData(sendData.ToString()); }
public static JsonArray reactToJSON(Object[] readableArray) { JsonArray jsonArray = new JsonArray(); for (int i = 0; i < readableArray.Length; i++) { Object value = readableArray[i]; if (value == null) { jsonArray.Add(null); } else if (value is bool) { jsonArray.Add(JsonValue.CreateBooleanValue(Boolean.Parse(value.ToString()))); } else if (value is double || value is int || value is float) { jsonArray.Add(JsonValue.CreateNumberValue(Double.Parse(value.ToString()))); } else if (value is string) { jsonArray.Add(JsonValue.CreateStringValue(value.ToString())); } else if (value is Dictionary <String, Object> ) { jsonArray.Add(reactToJSON((Dictionary <String, Object>)value)); } else if (value is Object[]) { jsonArray.Add(reactToJSON((Object[])value)); } } return(jsonArray); }
public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating) { JsonObject root = new Windows.Data.Json.JsonObject(); root.Add(jsonNameDeck, ToJson(gameDescription)); JsonArray expansionArray = new JsonArray(); Dominion.Expansion[] presentExpansions; Dominion.Expansion[] missingExpansions; gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions); foreach (var expansion in presentExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(true)); expansionArray.Add(expansionObject); } foreach (var expansion in missingExpansions) { JsonObject expansionObject = new JsonObject(); expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName())); expansionObject.Add("present", JsonValue.CreateBooleanValue(false)); expansionArray.Add(expansionObject); } root.Add(jsonNameRequiredExpansions, expansionArray); root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating)); return(root); }
/// <summary> /// 設定値をJSONに変換する. /// </summary> /// <returns>JSON</returns> public virtual JsonObject ToJson() { var obj = new JsonObject(); obj.Add(IsOnKey, JsonValue.CreateBooleanValue(this.IsOn)); return(obj); }
public static async void Stringify() { JsonObject jsonObject = new JsonObject(); if (Player.CurrentlyPlayingFile != null && !string.IsNullOrEmpty(Player.CurrentlyPlayingFile.Path)) { jsonObject[pathKey] = JsonValue.CreateStringValue(Player.CurrentlyPlayingFile.Path); jsonObject[posKey] = JsonValue.CreateNumberValue(Player.Position); } jsonObject[shuffleKey] = JsonValue.CreateBooleanValue(ShellVM.Shuffle); jsonObject[repeatKey] = JsonValue.CreateBooleanValue(ShellVM.Repeat); jsonObject[volKey] = JsonValue.CreateNumberValue(Player.Volume); StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("lastplaying.mc", CreationCollisionOption.ReplaceExisting); using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite)) { using (var outputStream = stream.GetOutputStreamAt(0)) { using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream)) { dataWriter.WriteString(jsonObject.Stringify()); await dataWriter.StoreAsync(); await outputStream.FlushAsync(); } } } }
public void SetAlwaysFinish(bool value) { var jsonObject = new JsonObject(); jsonObject["binPause"] = JsonValue.CreateBooleanValue(value); this.SetPreference(jsonObject); }
IJsonValue ParseAMF(Stream stream) { int type = (int)stream.ReadUInt8(); //1 switch (type) { case 0: return(JsonValue.CreateNumberValue(stream.ReadDouble(true))); //8 case 1: return(JsonValue.CreateBooleanValue(stream.ReadBoolean()));; //1 case 3: var data = new JsonObject(); while (true) { var l3 = (int)stream.ReadUInt16(); if (l3 == 0) { if (stream.ReadUInt8() == 9) { break; } } var s3 = stream.ReadString(l3); var d3 = ParseAMF(stream); data.Add(s3, d3); //n } return(data); case 2: var len = stream.ReadUInt16(); return(JsonValue.CreateStringValue(stream.ReadString((int)len))); //n case 8: var l8 = stream.ReadUInt32(); var obj = new JsonObject(); for (int i = 0; i < l8; i++) { var key = stream.ReadString((int)stream.ReadUInt16()); //2+n var val = ParseAMF(stream); //n obj.Add(key, val); } return(obj); case 9: return(null); //END case 10: var l10 = stream.ReadUInt32(); var arr = new JsonArray(); for (int i = 0; i < l10; i++) { var val = ParseAMF(stream); //n arr.Add(val); } return(arr); default: throw new Exception("JsonValue:" + type); } }
public void SetEdgeClean(bool value) { var jsonObject = new JsonObject(); jsonObject["openOnly"] = JsonValue.CreateBooleanValue(!value); this.SetPreference(jsonObject); }
/// <summary> /// Creates and returns a JSON Object of the instance. /// </summary> /// <returns>a JSON object of the instance</returns> public JsonObject ToJsonObject() { JsonObject jsonObject = new JsonObject(); jsonObject.SetNamedValue("Id", JsonValue.CreateNumberValue(this.Id)); jsonObject.SetNamedValue("Title", JsonValue.CreateStringValue(this.Title)); jsonObject.SetNamedValue("Author", JsonValue.CreateStringValue(this.Author)); jsonObject.SetNamedValue("PublicationDate", JsonValue.CreateStringValue(this.PublicationDate.ToString())); jsonObject.SetNamedValue("DishType", this.DishType.ToJsonObject()); jsonObject.SetNamedValue("Rating", this.Rating.ToJsonObject()); jsonObject.SetNamedValue("Difficulty", this.Difficulty.ToJsonObject()); jsonObject.SetNamedValue("Cost", this.Cost.ToJsonObject()); jsonObject.SetNamedValue("Vegetarian", JsonValue.CreateBooleanValue(this.Vegetarian)); jsonObject.SetNamedValue("HtmlReceipe", JsonValue.CreateStringValue("HtmlReceipe")); if (this.ToDoInstructions != null && this.ToDoInstructions != "") { jsonObject.SetNamedValue("ToDoInstructions", JsonValue.CreateStringValue(this.ToDoInstructions)); } jsonObject.SetNamedValue("WithAlcohol", JsonValue.CreateBooleanValue(this.WithAlcohol)); jsonObject.SetNamedValue("Image", JsonValue.CreateStringValue(this.Image)); jsonObject.SetNamedValue("Description", JsonValue.CreateStringValue("Description")); JsonArray ingredientsJson = new JsonArray(); foreach (Ingredient ingredient in ingredients) { ingredientsJson.Add(ingredient.ToJsonObject()); } jsonObject.SetNamedValue("Ingredients", ingredientsJson); return(jsonObject); }
public JsonObject ToJson(List <PropertyItem> mappedPropItems) { // return a json object of the things we need to serialize JsonObject retval = new JsonObject(); JsonArray jPropList = new JsonArray(); JsonArray jNodeList = new JsonArray(); JsonArray scNames = new JsonArray(); JsonArray oSparql = new JsonArray(); foreach (String currSubname in this.subclassNames) { scNames.Add(JsonValue.CreateStringValue(currSubname)); } // add properties foreach (PropertyItem p in this.props) { // check to see if the node was compressed by removing stuff not in use. if (mappedPropItems == null || p.GetIsReturned() || p.getConstraints() != null || mappedPropItems.Contains(p)) { jPropList.Add(p.ToJson()); } } // add nodes foreach (NodeItem n in this.nodes) { // if we're deflating, only add connected nodes if (mappedPropItems == null || n.GetConnected()) { jNodeList.Add(n.toJson()); } } if (this.instanceFromQueryConstructSparqlIds != null) { foreach (String os in this.instanceFromQueryConstructSparqlIds) { oSparql.Add(JsonValue.CreateStringValue(os)); } } // build the outgoing object retval.Add("originalInstanceSparqlIds", oSparql); retval.Add("propList", jPropList); retval.Add("nodeList", jNodeList); retval.Add("NodeName", JsonValue.CreateStringValue(this.nodeName)); retval.Add("fullURIName", JsonValue.CreateStringValue(this.fullURIname)); retval.Add("SparqlID", JsonValue.CreateStringValue(this.sparqlID)); retval.Add("isReturned", JsonValue.CreateBooleanValue(this.isReturned)); retval.Add("valueConstraint", JsonValue.CreateStringValue(this.GetValueConstraintStr())); if (this.instanceValue != null) { retval.Add("instanceValue", JsonValue.CreateStringValue(this.GetInstanceValue())); } retval.Add("isRuntimeConstrained", JsonValue.CreateBooleanValue(this.GetIsRuntimeConstrained())); retval.Add("deletionMode", JsonValue.CreateStringValue(Enum.GetName(typeof(NodeDeletionTypes), this.deletionMode))); retval.Add("subClassNames", scNames); return(retval); }
public static JsonObject Serialize(ThemePreset preset) { JsonObject data = new JsonObject(); if (!string.IsNullOrEmpty(preset.Id)) { data["Id"] = JsonValue.CreateStringValue(preset.Id); } if (!string.IsNullOrEmpty(preset.Name)) { data["Name"] = JsonValue.CreateStringValue(preset.Name); } void SerializeBlock(Color color, string colorNodeName, Dictionary <int, Color> overrides = null, string overridesNodeName = null, Dictionary <int, (bool, double, double?)> acrylicOverrides = null, string acrylicOverridesNodeName = null) { data[colorNodeName] = JsonValue.CreateStringValue(color.ToString()); if (overrides != null && !string.IsNullOrEmpty(overridesNodeName)) { var overridesNode = new JsonArray(); foreach (int index in overrides.Keys) { JsonObject node = new JsonObject(); node["Index"] = JsonValue.CreateNumberValue(index); node["Color"] = JsonValue.CreateStringValue(overrides[index].ToString()); overridesNode.Add(node); } data[overridesNodeName] = overridesNode; } if (acrylicOverrides != null && !string.IsNullOrEmpty(acrylicOverridesNodeName)) { var acrylicOverridesNode = new JsonArray(); foreach ((int index, (bool isHostBackdrop, double tintOpacity, double?tintLuminosityOpacity)) in acrylicOverrides) { JsonObject node = new JsonObject(); node["Index"] = JsonValue.CreateNumberValue(index); node["TintOpacity"] = JsonValue.CreateNumberValue(tintOpacity); node["IsHostBackdrop"] = JsonValue.CreateBooleanValue(isHostBackdrop); var tintLuminosityOpacityString = (tintLuminosityOpacity == null) ? "null": tintLuminosityOpacity.ToString(); node["TintLuminosityOpacity"] = JsonValue.CreateStringValue(tintLuminosityOpacityString); acrylicOverridesNode.Add(node); } data[acrylicOverridesNodeName] = acrylicOverridesNode; } } SerializeBlock(preset.LightRegionColor, nameof(LightRegionColor), preset.LightRegionOverrides, nameof(LightRegionOverrides), preset.LightRegionAcrylicOverrides, nameof(LightRegionAcrylicOverrides)); SerializeBlock(preset.DarkRegionColor, nameof(DarkRegionColor), preset.DarkRegionOverrides, nameof(DarkRegionOverrides), preset.DarkRegionAcrylicOverrides, nameof(DarkRegionAcrylicOverrides)); SerializeBlock(preset.LightBaseColor, nameof(LightBaseColor), preset.LightBaseOverrides, nameof(LightBaseOverrides)); SerializeBlock(preset.DarkBaseColor, nameof(DarkBaseColor), preset.DarkBaseOverrides, nameof(DarkBaseOverrides)); SerializeBlock(preset.LightPrimaryColor, nameof(LightPrimaryColor), preset.LightPrimaryOverrides, nameof(LightPrimaryOverrides)); SerializeBlock(preset.DarkPrimaryColor, nameof(DarkPrimaryColor), preset.DarkPrimaryOverrides, nameof(DarkPrimaryOverrides)); SerializeBlock(preset.LightHyperlinkColor, nameof(LightHyperlinkColor), preset.LightHyperlinkOverrides, nameof(LightHyperlinkOverrides)); SerializeBlock(preset.DarkHyperlinkColor, nameof(DarkHyperlinkColor), preset.DarkHyperlinkOverrides, nameof(DarkHyperlinkOverrides)); return(data); }
internal async Task SaveSettings() //保存设置 { StorageFolder folder = ApplicationData.Current.RoamingFolder; //获取应用目录的文件夹 var file_demonstration = await folder.CreateFileAsync("settings.json", CreationCollisionOption.ReplaceExisting); //创建文件 JsonObject json = new JsonObject() { ["totalSeconds"] = JsonValue.CreateNumberValue(Model.Second), ["fullScreen"] = JsonValue.CreateBooleanValue(Model.FullScreen), ["autoAdd"] = JsonValue.CreateBooleanValue(Model.AutoAdd), ["tileRefresh"] = JsonValue.CreateBooleanValue(Model.TileFresh), ["displayRequest"] = JsonValue.CreateBooleanValue(Model.DisplayRequest), ["playAudio"] = JsonValue.CreateBooleanValue(Model.PlayAudio), }; using (Stream file = await file_demonstration.OpenStreamForWriteAsync()) { using (StreamWriter write = new StreamWriter(file)) { await write.WriteAsync(json.ToString()); } } }
/// <summary> /// 設定値をJSONに変換する. /// </summary> /// <returns>JSON</returns> public override JsonObject ToJson() { var obj = base.ToJson(); obj.Add(ShouldAskUserKey, JsonValue.CreateBooleanValue(this.ShouldAskUser)); return(obj); }
/// <summary> /// Adds or updates a favorite. /// </summary> /// <param name="connectionData">The connection data of the favorite to add/update.</param> public void AddOrUpdate(ConnectionData connectionData) { var favorites = GetFavoritesSettings(); if (connectionData.Id == null) { connectionData.Id = Guid.NewGuid().ToString(); } JsonObject jsonObject = new JsonObject(); jsonObject.Add("Name", JsonValue.CreateStringValue(connectionData.Name)); jsonObject.Add("Type", JsonValue.CreateStringValue(connectionData.Type.ToString())); jsonObject.Add("Host", JsonValue.CreateStringValue(connectionData.Host)); jsonObject.Add("Port", JsonValue.CreateNumberValue((double)connectionData.Port)); jsonObject.Add("Username", JsonValue.CreateStringValue(connectionData.Username)); jsonObject.Add("Authentication", JsonValue.CreateStringValue(connectionData.Authentication.ToString())); jsonObject.Add("PrivateKeyName", JsonValue.CreateStringValue(connectionData.PrivateKeyName)); jsonObject.Add("PrivateKeyAgentForwarding", JsonValue.CreateBooleanValue(connectionData.PrivateKeyAgentForwarding)); string favoriteJsonString = jsonObject.Stringify(); favorites[connectionData.Id] = favoriteJsonString; this.favorites.Remove(GetFavorite(connectionData.Id)); this.favorites.Add(connectionData); }
public string Stringify() { JsonArray jsonArray = new JsonArray(); foreach (School school in Education) { jsonArray.Add(school.ToJsonObject()); } JsonObject jsonObject = new JsonObject(); jsonObject[idKey] = JsonValue.CreateStringValue(Id); // Treating a blank string as null if (String.IsNullOrEmpty(Phone)) { jsonObject[phoneKey] = JsonValue.CreateNullValue(); } else { jsonObject[phoneKey] = JsonValue.CreateStringValue(Phone); } jsonObject[nameKey] = JsonValue.CreateStringValue(Name); jsonObject[educationKey] = jsonArray; jsonObject[timezoneKey] = JsonValue.CreateNumberValue(Timezone); jsonObject[verifiedKey] = JsonValue.CreateBooleanValue(Verified); return(jsonObject.Stringify()); }
public void TestWriteDataJson() { Assert.AreEqual("null", JSON.Stringify(JsonValue.CreateNullValue())); Assert.AreEqual("true", JSON.Stringify(JsonValue.CreateBooleanValue(true))); Assert.AreEqual("1234", JSON.Stringify(JsonValue.CreateNumberValue(1234))); Assert.AreEqual("1234.5", JSON.Stringify(JsonValue.CreateNumberValue(1234.5))); Assert.AreEqual("\"Hello\"", JSON.Stringify(JsonValue.CreateStringValue("Hello"))); Assert.AreEqual("[1,false,\"xyz\",4.5,{},[]]", JSON.Stringify(new JsonArray { JsonValue.CreateNumberValue(1), JsonValue.CreateBooleanValue(false), JsonValue.CreateStringValue("xyz"), JsonValue.CreateNumberValue(4.5), new JsonObject(), new JsonArray(), })); Assert.AreEqual(@"{""aNumber"":123,""aBool"":true,""aString"":""abc"",""aArray"":[1,2,3],""aObject"":{""key"":""value"",""null"":null}}", JSON.Stringify(new JsonObject { { "aNumber", JsonValue.CreateNumberValue(123) }, { "aBool", JsonValue.CreateBooleanValue(true) }, { "aString", JsonValue.CreateStringValue("abc") }, { "aArray", new JsonArray { JsonValue.CreateNumberValue(1), JsonValue.CreateNumberValue(2), JsonValue.CreateNumberValue(3) } }, { "aObject", new JsonObject { { "key", JsonValue.CreateStringValue("value") }, { "null", JsonValue.CreateNullValue() } } }, })); }
private void CreateDynamicDeckConfigs(JsonObject dynamicDeck, JsonObject deck) { switch (studyOption) { case CustomStudyOption.ReviewForgotten: dynamicDeck["delays"] = CreateNumberArray(1); dynamicDeck.GetNamedArray("terms")[0] = CreateTermArray( "rated:" + numberBox.Number + ":1", MAX_NUMBER, (int)DynamicDeckOrder.RANDOM); dynamicDeck["resched"] = JsonValue.CreateBooleanValue(false); break; case CustomStudyOption.ReviewAhead: dynamicDeck["delays"] = JsonValue.CreateNullValue(); dynamicDeck.GetNamedArray("terms")[0] = CreateTermArray( "prop:due<=" + numberBox.Number, MAX_NUMBER, (int)DynamicDeckOrder.DUE); dynamicDeck["resched"] = JsonValue.CreateBooleanValue(true); break; case CustomStudyOption.PreviewNew: dynamicDeck["delays"] = JsonValue.CreateNullValue(); dynamicDeck.GetNamedArray("terms")[0] = CreateTermArray( "is:new added:" + numberBox.Number, MAX_NUMBER, (int)DynamicDeckOrder.OLDEST); dynamicDeck["resched"] = JsonValue.CreateBooleanValue(false); break; case CustomStudyOption.CramMode: StringBuilder tags = new StringBuilder(); AdvancedSearchPopup.AppendTags(tags, "tag:", includeTagsViewModel); AdvancedSearchPopup.AppendTags(tags, "-tag:", excludeTagsViewModel); dynamicDeck["delays"] = JsonValue.CreateNullValue(); dynamicDeck.GetNamedArray("terms")[0] = CreateTermArray( tags.ToString().Trim(), cramNumberBox.Number, (int)DynamicDeckOrder.RANDOM); if (rescheduleCheckBox.IsChecked == true) { dynamicDeck["resched"] = JsonValue.CreateBooleanValue(true); } else { dynamicDeck["resched"] = JsonValue.CreateBooleanValue(false); } break; default: break; } string term = dynamicDeck.GetNamedArray("terms").GetArrayAt(0).GetStringAt(0); term = "deck:\"" + deck.GetNamedString("name") + "\" " + term; dynamicDeck.GetNamedArray("terms").GetArrayAt(0)[0] = JsonValue.CreateStringValue(term); }
public void CollapseBrowser(long deckId) { JsonObject deck = Get(deckId); string browCollap = "browserCollapsed"; bool collapsed = deck.GetNamedBoolean(browCollap, false); deck[browCollap] = JsonValue.CreateBooleanValue(!collapsed); }
public void Collapse(long deckId) { JsonObject deck = Get(deckId); deck["collapsed"] = JsonValue.CreateBooleanValue(!deck.GetNamedBoolean("collapsed")); Save(deck); }
public void SaveOptionsToJsonConfig() { Config["perDay"] = JsonValue.CreateNumberValue(Options.PerDay); Config["ease4"] = JsonValue.CreateNumberValue(Options.EasyBonus / 100.0); Config["ivlFct"] = JsonValue.CreateNumberValue(Options.IvlFct / 100.0); Config["maxIvl"] = JsonValue.CreateNumberValue(Options.MaxIvl); Config["bury"] = JsonValue.CreateBooleanValue(Options.Bury); }
public void SaveOptionsToJsonConfig() { Config["dueCounts"] = JsonValue.CreateBooleanValue(Options.IsShowDueCount); Config["estTimes"] = JsonValue.CreateBooleanValue(Options.IsShowEstTime); Config["newSpread"] = JsonValue.CreateNumberValue(Options.ReviewType); CopyOptions(Options, oldOptions); }
public void SaveOptions() { Config["dueCounts"] = JsonValue.CreateBooleanValue(Options.IsShowDueCount); Config["estTimes"] = JsonValue.CreateBooleanValue(Options.IsShowEstTime); Config["newSpread"] = JsonValue.CreateNumberValue(Options.ReviewType); MainPage.UserPrefs.IsAutoPlayTextSynth = Options.IsTTSAutoplay; CopyOptions(Options, oldOptions); }
public new string ToString() { JsonObject jsonObject = new JsonObject(); jsonObject.SetNamedValue("Name", JsonValue.CreateStringValue(Name)); jsonObject.SetNamedValue("Url", JsonValue.CreateStringValue(Url)); jsonObject.SetNamedValue("UseProxy", JsonValue.CreateBooleanValue(UseProxy)); return(jsonObject.ToString()); }
public JsonObject Chunk() { JsonObject buf = new JsonObject(); buf.Add("done", JsonValue.CreateBooleanValue(false)); int lim = 250; while (!(tablesLeft.Count == 0) && lim > 0) { string curTable = tablesLeft.First(); var listObject = CursorForTable(curTable); JsonArray rows = new JsonArray(); int fetched = 0; for (int i = currentCursor; i < listObject.Count; i++) { JsonArray r = new JsonArray(); foreach (object obj in listObject[i]) { if (obj is String) { r.Add(JsonValue.CreateStringValue(Convert.ToString(obj))); } else { r.Add(JsonValue.CreateNumberValue(Convert.ToDouble(obj))); } } rows.Add(r); fetched++; if (fetched == lim) { currentCursor += fetched; break; } } if (fetched != lim) { // table is empty tablesLeft.RemoveFirst(); currentCursor = 0; // if we're the client, mark the objects as having been sent if (!collection.IsServer) { collection.Database.Execute("UPDATE " + curTable + " SET usn=" + maxUsn + " WHERE usn=-1"); } } buf.Add(curTable, rows); lim -= fetched; } if (tablesLeft.Count == 0) { buf["done"] = JsonValue.CreateBooleanValue(true); } return(buf); }
public JsonObject ToJsonObject() { JsonObject jsonObject = new JsonObject(); jsonObject.SetNamedValue(nameKey, JsonValue.CreateStringValue(this.name)); jsonObject.SetNamedValue(colorKey, JsonValue.CreateStringValue(this.color.ToString())); jsonObject.SetNamedValue(noiseKey, JsonValue.CreateBooleanValue(this.isIgnored)); jsonObject.SetNamedValue(ignoredKey, JsonValue.CreateBooleanValue(this.isNoise)); return(jsonObject); }
public string Stringify() { JsonObject jsonObject = new JsonObject(); addString(jsonObject, "title", title); addString(jsonObject, "artist", artist); addString(jsonObject, "album", album); jsonObject["playing"] = JsonValue.CreateBooleanValue(playing); return(jsonObject.Stringify()); }
/// <summary> /// Handles "GetProducts" request and returns data of products of give category to UWA /// </summary> private static IAsyncOperation <AppServiceResponseStatus> SendProductsByCategoryAsync(AppServiceRequest request, int categoryId) { ConsoleColor oldColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Received GetProducts request for category id: \"{0}\".", categoryId); ValueSet returnValues = new ValueSet(); try { var db = new Database(dbFileFolder); // Serialize all DB query results into JSON // Because AppService only support passing data of primitive types int count = 0; JsonArray products = new JsonArray(); foreach (var prod in db.GetProductsByCategory(categoryId)) { Console.WriteLine("Adding return value. {0} : {1}", count.ToString(), prod.Name); JsonObject jsonProd = new JsonObject(); jsonProd.Add("ID", JsonValue.CreateNumberValue(prod.ID)); jsonProd.Add("Name", JsonValue.CreateStringValue(prod.Name)); jsonProd.Add("QuantityPerUnit", JsonValue.CreateStringValue(prod.QuantityPerUnit)); jsonProd.Add("UnitPrice", JsonValue.CreateNumberValue(prod.UnitPrice)); jsonProd.Add("UnitsInStock", JsonValue.CreateNumberValue(prod.UnitsInStock)); jsonProd.Add("UnitsOnOrder", JsonValue.CreateNumberValue(prod.UnitsOnOrder)); jsonProd.Add("ReorderLevel", JsonValue.CreateNumberValue(prod.ReorderLevel)); jsonProd.Add("Discontinued", JsonValue.CreateBooleanValue(prod.Discontinued)); jsonProd.Add("SupplierID", JsonValue.CreateNumberValue(prod.SupplierID)); jsonProd.Add("CategoryID", JsonValue.CreateNumberValue(prod.CategoryID)); products.Add(jsonProd); count++; } returnValues.Add("Result", products.Stringify()); Console.WriteLine("Adding return value. {0} : {1}", "ResultCount", count); returnValues.Add("ResultCount", count); Console.WriteLine("Adding return value. {0} : {1}", "ErrorMessage", "Succeeded"); returnValues.Add("ErrorMessage", "Succeeded"); Console.WriteLine("Sending result with \"{0}\" products", count); Console.WriteLine(); Console.ForegroundColor = oldColor; } catch (Exception e) { Console.WriteLine(e.Message); returnValues.Add("ErrorMessage", e.Message); } return(request.SendResponseAsync(returnValues)); }
private JsonObject GetImageData(CreateTilePage_ImageViewModel m) { JsonObject data = new JsonObject(); if (m.ImageSource != null) { data.Add("src", JsonValue.CreateStringValue((m.ImageSource as BitmapImage).UriSource.AbsolutePath)); } data.Add("title", JsonValue.CreateBooleanValue(m.ShowTitle)); return(data); }
public void Append() { JsonArray array = null; array.Append(JsonValue.CreateStringValue("test")); array = new JsonArray() .Append(JsonValue.CreateBooleanValue(true)) .Append(JsonValue.CreateStringValue("test")); Assert.AreEqual(2, array.Count); }