C# Couchbase Lite文档缺少属性

C# Couchbase Lite文档缺少属性,c#,json,xamarin,couchbase,couchbase-lite,C#,Json,Xamarin,Couchbase,Couchbase Lite,我一直在跨平台(Xamarin)应用程序项目中使用Couchbase Lite作为本地数据存储。我一直在从Amazon Web服务后端检索对象,使用Newtonsoft JSON进行序列化。我的对象中的所有内容都正确序列化,因为我在几周前回答了这个问题。但是,在couchbase lite中将我的食谱的“组”属性添加到文档中失败。保存文档时不会引发异常,但从数据库检索文档时,“IngredientsWithHeaders”和“InstructionWithHeaders”都返回null。以下是保

我一直在跨平台(Xamarin)应用程序项目中使用Couchbase Lite作为本地数据存储。我一直在从Amazon Web服务后端检索对象,使用Newtonsoft JSON进行序列化。我的对象中的所有内容都正确序列化,因为我在几周前回答了这个问题。但是,在couchbase lite中将我的食谱的“组”属性添加到文档中失败。保存文档时不会引发异常,但从数据库检索文档时,“IngredientsWithHeaders”和“InstructionWithHeaders”都返回null。以下是保存/检索代码:

public void SaveRecipe (Recipe recipe)
    {
        var document = db.GetDocument (recipe.RecipeId);
        var properties = new Dictionary<string, object> (){
            { "UserId",recipe.UserId },
            { "Title",recipe.Title },
            { "IngredientsList",recipe.IngredientsList },
            { "Notes",recipe.Notes },
            { "Tags",recipe.Tags },
            { "Yield",recipe.Yield },
            { "IngredientsWithHeaders",recipe.IngredientsWithHeaders },
            { "InstructionsWithHeaders",recipe.InstructionsWithHeaders }
        };
        var rev = document.PutProperties(properties);
        Debug.Assert (rev != null, "Revision is null");
        var newRev = document.CurrentRevision.CreateRevision ();
        newRev.SetAttachment ("image.jpg", "image/jpeg", recipe.Image);
        newRev.Save ();
    }

public IEnumerable<Recipe> GetRecipes ()
    {
        var query = db.CreateAllDocumentsQuery ();
        query.AllDocsMode = AllDocsMode.AllDocs;
        var rows = query.Run ();
        Debug.WriteLine ("Recipes in Query: "+rows.Count);
        return rows.Select (recipe => ToRecipe (recipe.Document));
    }

private Recipe ToRecipe(Document doc){
        Recipe recipe = new Recipe(doc.Id);
        recipe.UserId = doc.GetProperty<string> ("UserId");
        recipe.Title = doc.GetProperty<string> ("Title");
        recipe.IngredientsList = doc.GetProperty<List<string>> ("IngredientsList");
        recipe.Notes = doc.GetProperty<List<string>> ("Notes");
        recipe.Tags = doc.GetProperty<ISet<string>> ("Tags");
        recipe.Yield = doc.GetProperty<int> ("Yield");
        recipe.IngredientsWithHeaders = doc.GetProperty<List<Group<string,IngredientJson>>> ("IngredientsWithHeaders");
        recipe.InstructionsWithHeaders = doc.GetProperty<List<Group<string,string>>> ("InstructionsWithHeaders");
        var rev = doc.CurrentRevision;
        var image = rev.GetAttachment ("image.jpg");
        if (image != null) {
            Debug.WriteLine ("There is an image here");
            recipe.Image = image.Content.ToArray();
        }
        return recipe;
    }
public void SaveRecipe(配方)
{
var document=db.GetDocument(recipe.RecipeId);
var属性=新字典(){
{“UserId”,recipe.UserId},
{“Title”,recipe.Title},
{“IngredientsList”,recipe.IngredientsList},
{“Notes”,recipe.Notes},
{“Tags”,recipe.Tags},
{“产量”,recipe.Yield},
{“IngredientsWithHeaders”,recipe.IngredientsWithHeaders},
{“指令WithHeaders”,recipe.instructionWithHeaders}
};
var rev=文件属性(属性);
Assert(rev!=null,“Revision为null”);
var newRev=document.CurrentRevision.CreateRevision();
newRev.SetAttachment(“image.jpg”、“image/jpeg”、recipe.image”);
newRev.Save();
}
公共IEnumerable GetRecipes()
{
var query=db.CreateAllDocumentsQuery();
query.AllDocsMode=AllDocsMode.AllDocs;
var rows=query.Run();
Debug.WriteLine(“查询中的配方:+rows.Count”);
返回行。选择(recipe=>ToRecipe(recipe.Document));
}
私人配方托瑞普(文档文档){
配方=新配方(文档Id);
recipe.UserId=doc.GetProperty(“UserId”);
recipe.Title=doc.GetProperty(“Title”);
recipe.IngredientsList=doc.GetProperty(“IngredientsList”);
recipe.Notes=doc.GetProperty(“Notes”);
recipe.Tags=doc.GetProperty(“标签”);
recipe.Yield=doc.GetProperty(“Yield”);
recipe.IngreditSwithHeaders=doc.GetProperty(“IngreditSwithHeaders”);
recipe.InstructionsWithHeaders=doc.GetProperty(“InstructionsWithHeaders”);
var版本=文件当前版本;
var image=rev.GetAttachment(“image.jpg”);
如果(图像!=null){
Debug.WriteLine(“这里有一个图像”);
recipe.Image=Image.Content.ToArray();
}
返回配方;
}

ToRecipe()
方法更改为以下方法解决了问题:

private Recipe ToRecipe(Document doc){
    Recipe recipe = new Recipe(doc.Id);
    recipe.UserId = doc.GetProperty<string> ("UserId");
    recipe.Title = doc.GetProperty<string> ("Title");
    recipe.IngredientsList = doc.GetProperty<List<string>> ("IngredientsList");
    recipe.Notes = doc.GetProperty<List<string>> ("Notes");
    recipe.Tags = doc.GetProperty<ISet<string>> ("Tags");
    recipe.Yield = doc.GetProperty<int> ("Yield");
    recipe.IngredientsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, IngredientJson>>>(doc.GetProperty ("IngredientsWithHeaders").ToString());

    recipe.InstructionsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, string>>>(doc.GetProperty("InstructionsWithHeaders").ToString());

    var rev = doc.CurrentRevision;
    var image = rev.GetAttachment ("image.jpg");
    if (image != null) {
        Debug.WriteLine ("There is an image here");
        recipe.Image = image.Content.ToArray();
    }
    return recipe;
}
private Recipe-ToRecipe(文档文档){
配方=新配方(文档Id);
recipe.UserId=doc.GetProperty(“UserId”);
recipe.Title=doc.GetProperty(“Title”);
recipe.IngredientsList=doc.GetProperty(“IngredientsList”);
recipe.Notes=doc.GetProperty(“Notes”);
recipe.Tags=doc.GetProperty(“标签”);
recipe.Yield=doc.GetProperty(“Yield”);
recipe.IngreditSwithHeaders=JsonConvert.DeserializeObject(doc.GetProperty(“IngreditSwithHeaders”).ToString();
recipe.InstructionsWithHeaders=JsonConvert.DeserializeObject(doc.GetProperty(“InstructionsWithHeaders”).ToString();
var版本=文件当前版本;
var image=rev.GetAttachment(“image.jpg”);
如果(图像!=null){
Debug.WriteLine(“这里有一个图像”);
recipe.Image=Image.Content.ToArray();
}
返回配方;
}

ToRecipe()
方法更改为以下方法解决了问题:

private Recipe ToRecipe(Document doc){
    Recipe recipe = new Recipe(doc.Id);
    recipe.UserId = doc.GetProperty<string> ("UserId");
    recipe.Title = doc.GetProperty<string> ("Title");
    recipe.IngredientsList = doc.GetProperty<List<string>> ("IngredientsList");
    recipe.Notes = doc.GetProperty<List<string>> ("Notes");
    recipe.Tags = doc.GetProperty<ISet<string>> ("Tags");
    recipe.Yield = doc.GetProperty<int> ("Yield");
    recipe.IngredientsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, IngredientJson>>>(doc.GetProperty ("IngredientsWithHeaders").ToString());

    recipe.InstructionsWithHeaders = JsonConvert.DeserializeObject<List<Group<string, string>>>(doc.GetProperty("InstructionsWithHeaders").ToString());

    var rev = doc.CurrentRevision;
    var image = rev.GetAttachment ("image.jpg");
    if (image != null) {
        Debug.WriteLine ("There is an image here");
        recipe.Image = image.Content.ToArray();
    }
    return recipe;
}
private Recipe-ToRecipe(文档文档){
配方=新配方(文档Id);
recipe.UserId=doc.GetProperty(“UserId”);
recipe.Title=doc.GetProperty(“Title”);
recipe.IngredientsList=doc.GetProperty(“IngredientsList”);
recipe.Notes=doc.GetProperty(“Notes”);
recipe.Tags=doc.GetProperty(“标签”);
recipe.Yield=doc.GetProperty(“Yield”);
recipe.IngreditSwithHeaders=JsonConvert.DeserializeObject(doc.GetProperty(“IngreditSwithHeaders”).ToString();
recipe.InstructionsWithHeaders=JsonConvert.DeserializeObject(doc.GetProperty(“InstructionsWithHeaders”).ToString();
var版本=文件当前版本;
var image=rev.GetAttachment(“image.jpg”);
如果(图像!=null){
Debug.WriteLine(“这里有一个图像”);
recipe.Image=Image.Content.ToArray();
}
返回配方;
}

听起来与您在上一个问题中提到的序列化问题一模一样。你采取了什么方法来解决这个问题?我建议使用<代码>字典<代码>而不是<代码>组< /代码>。我确实考虑过,但是它似乎是正确地序列化到CoucBaseLite数据库中。出于某种原因,它只是没有反序列化为所需的类型。这听起来与您在上一个问题中提到的序列化问题完全相同。你采取了什么方法来解决这个问题?我建议使用<代码>字典<代码>而不是<代码>组< /代码>。我确实考虑过,但是它似乎是正确地序列化到CoucBaseLite数据库中。出于某种原因,它只是没有反序列化为所需的类型。