Details
-
Task
-
Resolution: Resolved
-
Major
-
Mobile 3.0
-
None
Description
Reference: https://ibsoln.github.io/stage/stage300/couchbase-lite/current/csharp/document.html
The current code snippet creates MutableArrayObject from JSON and then loop through the array to create a document from each item of the array. I think it's better and more simplify to just create one doc using the array object.
For Example:
Database dbNew = new Database(ourdbname); |
|
// JSON String -- an Array (3 elements. including embedded arrays)
|
var thisJSONstring = "['Hotel Ned', 'Hotel Ted']".Replace("'", "\""); |
|
// Create mutable array using JSON String Array
|
var hotels = new MutableArrayObject(json: thisJSONstring); |
|
// Create a document with the featured hotels array object
|
var newdoc = new MutableDocument("1002"); |
newDoc.SetArray("features", hotels) |
dbNew.Save(newdoc);
|
|
// Get document and access the featured hotels
|
var doc = dbNew.GetDocument("1002"); |
var features = doc.GetArray("features"); |
foreach (string feature in features) {
|
System.Console.Write(feature);
|
}
|
|
// Convert features hotels into JSON
|
var featuresJSON = features.ToJSON();
|