viezel / napp.alloy.adapter.restapi

RestAPI Sync Adapter for Titanium Alloy Framework
197 stars 102 forks source link

Parsing array response from server #18

Open dkrusenstrahle opened 11 years ago

dkrusenstrahle commented 11 years ago

Hello,

I am trying to parse this output (from an API):

{ "code": 200, "total": 1, "projects": [ { "project": { "id": 4, "title": "rebuilding school", "description": "Rebuilding of the school diner.", "created_at": "2013-09-24T15:59:10Z", "total_tasks": 2 } } ] }

I tried both this:

"parentNode": "projects.project",

and I have tried this:

"parentNode": "projects[0]project",

None of them creates the model. How can I access the title, id and so on?

Thanks!

viezel commented 11 years ago

look here: https://github.com/viezel/napp.alloy.adapter.restapi#nested-result-objects

You can either define the parent node, or specify a custom parsing function. In your example it would be

"parentNode": "projects"

Because each "project" is the item you want to parse, and therefore "projects" is the parent node.