Hi, I have a document with below json format. how i can get “Price” object to update “RetailPrice”
I tried below code but no luck.
var priceObj = database.GetDocument(id).ToMutable().GetDictionary(“ProductList.Price”);
var priceObj = database.GetDocument(id).ToMutable().GetArray(“ProductList[0].Price”);
@GPK
Couchbase Lite Document is a dictionary object. The dictionary value type can only be byte, sbyte, short, ushort, int, uint, long, ulong, float, double, bool, DateTimeOffset, Blob, a one-dimensional array or a dictionary whose members are one of the preceding types.
So in the cbl doc construction example you just provided, the doc should look something like
var p = new Dictionary<string, object> {
["id"] = testClass.Id,
["DocVrsn"] = testClass.DocVrsn,
["Type"] = testClass.Type,
["ProductList"] = new Dictionary<string, object> {
["ProductName"] = "sales",
["Price List"] = new List<Dictionary<string, object>>() {
new Dictionary<string, object> {
["RetailPrice"] = 1.50,
["WholesalePrice"] = 2.5
},
new Dictionary<string, object> {
["RetailPrice"] = 3.50,
["WholesalePrice"] = 4.5
}
}
}
};
var doc = new MutableDocument(testClass.Id, p);
Db.Save(doc);
then you can access ProductList like
var productList = Db.GetDocument("doc_sales_061720201").GetDictionary("ProductList");