@vkyralesov

Как вывести такую структуру json в Angularjs?

Нужно добиться такой структуры в json формате

{
    "project": [{
        "flag_count": 1,
        "is_featured": false,
        "is_commissioned": false,
        "is_shortlisted": false,
        "meta_json": {
            "themes": ["text", "text", "text", "text"],
            "technologies": {
                "libraries": ["Node.js", "Node.js", "Node.js", "Node.js", "Node.js", "Node.js", "Node.js"],
                "platforms": ["Web", "Web"],
                "apis": ["Google Plus", "Google Plus"]
            }
        },
        "profile": {
            "site_admin": false,
            "hireable": false,
            "id": 1,
            "accepted_tcs": true,
            "location": "Moscow",
            "type": "User",
            "email": "",
            "company": "Company Name",
            "html_url": "#",
            "name": "Kyralesov Creations",
            "created_at": "2014-01-25T14:52:41Z",
            "avatar_url": "#",
            "login": "username"
        },
        "is_finalist": false,
        "is_winner": false,
        "tags_data": {
            "themes": [{
                "term": "google compute engine",
                "taxonomy": "themes",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }, {
                "term": "web",
                "taxonomy": "themes",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }, {
                "term": "speech recognition",
                "taxonomy": "themes",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }, {
                "term": "interactive installation",
                "taxonomy": "themes",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }, {
                "term": "text analysis",
                "taxonomy": "themes",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }
            ],
            "languages": [{
                "term": "javascript",
                "taxonomy": "languages",
                "colour": "#F15501",
                "link_count": 1,
                "aliases": ["js", "java script"]
            }, {
                "term": "css",
                "taxonomy": "languages",
                "colour": "#1F085E",
                "link_count": 1,
                "aliases": ["css3", "css 3"]
            }, {
                "term": "arduino",
                "taxonomy": "languages",
                "colour": null,
                "link_count": 1,
                "aliases": []
            }
            ],
            "toolkits": [{
                "term": "webgl",
                "taxonomy": "toolkits",
                "colour": "#F15501",
                "link_count": 1,
                "aliases": ["web gl"]
            }
            ],
            "apis": [{
                "term": "web speech",
                "taxonomy": "apis",
                "colour": null,
                "link_count": 1,
                "aliases": ["google speech", "google web speech"]
            }, {
                "term": "g+",
                "taxonomy": "apis",
                "colour": null,
                "link_count": 1,
                "aliases": ["g +", "google plus", "googleplus", "google +", "google+"]
            }
            ]
        },
        "is_submitted": false,
        "name": "Name",
        "content_md": "# Title\n\n\n## Authors\n",
        "created": "2014-02-05T11:23:55.274220",
        "cover": {
            "url": "#"
        },
        "modified": "2014-10-13T19:00:21.743060",
        "full_name": "template",
        "content_html": "<h1>Заголовок</h1>\n\n<p></p>\n\n<p></p>",
        "is_pending": false,
        "is_published": true
    }],
    "meta": {
        "orders": {
            "project": "[PropertyOrder(<is_commissioned>, DESCENDING), BooleanProperty('is_winner', default=False), PropertyOrder(<is_finalist>, DESCENDING), PropertyOrder(<is_shortlisted>, DESCENDING), PropertyOrder(<modified>, DESCENDING)]",
            "post": {},
            "tag": {},
            "link": {},
            "inspiration": "[PropertyOrder(<modified>, DESCENDING)]"
        },
        "limit": 25,
        "ts": "2014-10-22 18:55:59.397860",
        "counters": {
            "search": {},
            "project": {
                "nFound": 203,
                "nReturned": 20,
                "more": true
            },
            "tag": {},
            "link": {},
            "post": {},
            "inspiration": {
                "nFound": 25,
                "nReturned": 5,
                "more": true
            }
        }
    }]}


Данные вытаскиваются с Mysql, сейчас как пример нашел такой вывод, но не понятно как сделать массив в массиве, что бы там была информация из БД
private function globals(){	
			if($this->get_request_method() != "GET"){
				$this->response('',406);
			}
			$query="SELECT distinct c.customerNumber, c.customerName, c.email, c.address, c.city, c.state, c.postalCode, c.country FROM angularcode_customers c order by c.customerNumber desc";
			$r = $this->mysqli->query($query) or die($this->mysqli->error.__LINE__);
			
			$queryy="SELECT distinct c.customerNumber, c.customerName, c.email, c.address, c.city, c.state, c.postalCode, c.country FROM angularcode_customers c order by c.customerNumber desc";
			$rr = $this->mysqli->query($queryy) or die($this->mysqli->error.__LINE__);
			$queryyy="SELECT distinct c.customerNumber, c.customerName, c.email, c.address, c.city, c.state, c.postalCode, c.country FROM angularcode_customers c order by c.customerNumber desc";
			$rrr = $this->mysqli->query($queryyy) or die($this->mysqli->error.__LINE__);
						$queryyyy="SELECT distinct c.customerNumber, c.customerName, c.email, c.address, c.city, c.state, c.postalCode, c.country FROM angularcode_customers c order by c.customerNumber desc";
			$rrrr = $this->mysqli->query($queryyyy) or die($this->mysqli->error.__LINE__);

			if($r->num_rows > 0){
				
				 $response["project"]   = array();
				 $response["meta"]   = array();
				 $response["inspiration"]   = array();

				while($row = $r->fetch_assoc()){
					$result = array();
					
					
					$result['flag_count'] = '12';
					$result['is_featured'] = false;
					$result['is_commissioned'] = false;
					$result['is_shortlisted'] = false;
					$result['meta_json'] = array('themes' => array("Speech recognition", "WebGL", "interactive installation", "text analysis"), 'technologies' => array('libraries'=>array("Node.js", "Three.js", "Mongodb", "Mongoose", "Passport", "Sentimental", "Socket.IO"), 'platforms' => array("Google Compute Engine", "Web"), 'apis' =>array("xyz", "Google Plus")));
					array_push($response["project"], $result);
					}
				
				$this->response($this->json($response), 200); // send user details
			}
			$this->response('',204);	// If no records "No Content" status
		}

В php как пример того что я пытался добиться той структуры что мне нужна в итоге. Но мне кажется что я не на очень верном пути, уважаемые объясните.
  • Вопрос задан
  • 2905 просмотров
Пригласить эксперта
Ответы на вопрос 1
Массив в массиве, один из способов чтобы понимали как это работает
$data_nested = array('first_key' => 'first', 'second_key' => 'second');

$data = array();

$data['single'] = 'single value';
$data['nested'] = $data_nested;

echo $data['nested']['second_key']; // second


и да, как сформировали массив
echo json_encode($data);

для преобразования php массива в json данные для ангуляра.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы