Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Json Advice

$
0
0
I just hit a roadblock...hoping someone has some ideas.

my data returned in json format looks like this...

"response": {
        "status": "OK",
        "content-categories": [
            {
                "id": 1,
                "name": "Pets & Animals",
                "description": null,
                "is_system": true,
                "parent_category": null,
                "type": "standard",
                "code": null,
                "last_modified": "2010-10-22 18:58:13"
            },
....



I can process most jsons just fine but this one is unique.
It seems "content-categories" really messes up Yii.

if ($api == "content-category")
	 {
		for ($i=0 ; $i<$limit; $i++) {
			$cc = new ContentCategory;			
			$cc->id = $obj->response->content-categories[$i]->id;
			$cc->category = $obj->response->content-categories[$i]->name;
			$cc->description = $obj->response->content-categories[$i]->description;
			$cc->is_system = $obj->response->content-categories[$i]->is_system;
			$cc->parent_id = $obj->response->content-categories[$i]->parent_category[0]->id;
			$cc->type = $obj->response->content-categories[$i]->type;
			$cc->code = $obj->response->content-categories[$i]->code;
			$cc->last_modified = $obj->response->content-categories[$i]->last_modified;

			$cc->save(false);
		}

	 }

I tried to make the $obj reference dynamic in my controller but that didn't work either. "$api" substituted for "content-categories"

if ($api == "content-category")
	 {
		for ($i=0 ; $i<$limit; $i++) {
			$cc = new ContentCategory;			
			$cc->id = $obj->response->$api[$i]->id;
			$cc->category = $obj->response->$api[$i]->name;
			...
			$cc->save(false);
		}

	 }


With the existance of references to the dash "-" it causes the Yii controller to error out when calling anything (in this case another view that loads up a control panel to call the controller function)

$cc->id = $obj->response->content-categories[$i]->id;

Anyone have advice on how to deal with this? I can't control the JSON output, the object will have a dash in this case.
In another case it does not, they used "_" underscore, which worked fine.

Viewing all articles
Browse latest Browse all 18717

Trending Articles