Couchbase, JSON objects inside a Document(CBLModel)

77 views
Skip to first unread message

Souhail Marghabi

unread,
Mar 24, 2015, 7:00:30 AM3/24/15
to mobile-c...@googlegroups.com
Greetings Everyone,

I am developing an iOS where I use CBModel to parse documents from my database. I am facing an issue/confusion when attempting to parse a document below with a type but that has an object inside(not a document), my data looks as such:
{
  "codeCouleur": "115,194,251",
  "groupeOffre": "DIGITAL_CUSTOMER_XP",
  "idImageHeader": "image:658899-4567",
  "idImagePrincipale": "image:877676-6577",
  "idPictogramme": "image:679865-7990",
  "traductions": [
    {
      "detailHtml": "<h1>Moderne et innovant</h1><p>Le Creative Studio vous accompagne pour la conception de vos projets digitaux. L'effet wow en plus</p><hr />[image1]<h2>ERGONOMIE</h2><p>Le Creative Studio est convaincu que l'ergonomie est un facteur crucial pour la réussite pour un projet site web ou d'application. ...</p>",
      "imagesDetailHtml": {
        "image1": "image:image_guillaume:b10fc2c7-78d6-4bac-bbfa-1d6816224360"
      },
      "langue": "fr",
      "nom": "Creative Studio",
      "texteAccroche": "Découvrer des design sur mesure"
    }
  ],
  "type": "Offre"
}

My issue is how I would parse this document that has an array "traductions" that has two objects  inside it(nested objects I think) that is inside the "offre" document.  My knowledge for couchebase iOS comes from the samples provided but none address such scenario. Any help would be appreciated.

Jens Alfke

unread,
Mar 24, 2015, 12:39:08 PM3/24/15
to mobile-c...@googlegroups.com

On Mar 24, 2015, at 4:00 AM, Souhail Marghabi <souhail....@gmail.com> wrote:

My issue is how I would parse this document that has an array "traductions" that has two objects  inside it(nested objects I think) that is inside the "offre" document.  My knowledge for couchebase iOS comes from the samples provided but none address such scenario. Any help would be appreciated.

Create a custom class that implements the JSONEncoding protocol (found in CBLJSON.h).
Implement the methods to read and write the class’s properties from an NSDictionary.
In your CBLModel subclass declare the property “traductions” as an NSArray.
Implement +traductionsItemClass to return your custom class (not an instance, but the class object itself.)

—Jens
Reply all
Reply to author
Forward
0 new messages