V
V
vkyralesov2014-10-25 17:51:43
PHP
vkyralesov, 2014-10-25 17:51:43

How to output such json structure in Angularjs?

You need to achieve such a structure in json format

{
    "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
            }
        }
    }]}

The data is pulled out from Mysql, now as an example I found such a conclusion, but it’s not clear how to make an array in an array, so that there would be information from the database
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
    }

In php, as an example of what I was trying to achieve the structure that I need in the end. But it seems to me that I'm not on the right track, dear explain.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sydorenko, 2014-10-25
@San40

An array within an array, one way to understand how it works

$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

and yes, how was the array formed
to convert the php array into json data for angular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question