How to retrive keys and values in nested array and list?


#1

Hello,

I have document structure in Couchbase like this

{
“key” : “xxx”,
“list” :
[
{
“itemA” : “xxx”,
“itemB” :
{“itemB-1” : “xxx”, “itemB-2” : “xxx”}
}

    {
    "itemA" : "xxx",
    "itemB" : 
        {"itemB-1" : "xxx", "itemB-2" : "xxx"}
    }

]

How can I retrive “ItemA” and “itemB-1” level by using Get() or GetJson() or other method?

I saw “NCBC-316: Allow GetJson to support the retrieval of arrays and lists:”(https://www.couchbase.com/issues/browse/NCBC-316)

and tried .NET SDK 1.3.3 but failed.


#2

Hi Cloudy -

The NCBC you linked to solves a different use case: storing lists and arrays of data as JSON; it doesn’t relate to documents with nested JSON arrays.

In order to do this, you would need to create a view. Here are a couple of resources to get you started:

  • http://docs.couchbase.com/couchbase-sdk-net-1.3/#working-with-views
  • http://docs.couchbase.com/couchbase-manual-2.0/#view-and-query-pattern-samples

Take a crack at it and let me know if you get stuck!

-Jeff


#3

Hi Jeff

Thx for your reply.

Actually, I already had a view was changed for performance this time.
So I found the way to approach the items in API support .

I made 2 classes,

public class tmpDOC
{
[JsonProperty]
public String key;

[JsonProperty]
public String itemA;

[JsonProperty]
public List list;

}

public class tmpList
{
[JsonProperty]
public String itemB-1;

}

and I got doc with GetJson() like I thought first.

tmpDoc = client.GetJson(key);

If I need to handle more nested Json doc later,
I think it needs more classes or have to parse/handle the doc in application level.

bye~ :slight_smile:


#4

something wrong in my comment.
I tried to edit my comment but access denied.