I Have this project where I want to get the JSON data from an Open Dataset . I need to use NodeJS to get this JSON info from this dataset and pass it to angular. The problem is that I'm passing a JSON-file instead of a JSON object so I can't use the usual Angular functions like ng-repeat
on this data. I'm guessing I need to Parse this JSON in NodeJS first, but HOW do I do this? How do I parse this JSON and only pass the requested objects back to my angular?
NodeJS code for getting the full JSON from the dataset to Angular:
app.post("/", function (req, res) {
request("http://datasets.antwerpen.be/v1/bevolking/inkomensvolgenswoonplaatsperdistrict.json").pipe(res);
})
so I angular I will get the entire JSON, but this is neither efficient/fast, nor is it possible for me to handle the data in Angular.
I tried the url you gave and it returns an object which contain an array of objects. I guess you want the ng-repeat to run through that array vs the top parent object?
if you know the top parent key (which was 'inkomensvolgenswoonplaatsperdistrict' when I tested) you can tell angular to use it, like this:
<div ng-repeat="(key, value) in myObj.inkomensvolgenswoonplaatsperdistrict"> ... </div>
which will tell angular to run through the array.
If you want to handle this at the node level, you can do the following:
app.post("/", function (req, res) {
request("http://datasets.antwerpen.be/v1/bevolking/inkomensvolgenswoonplaatsperdistrict.json", function (error, response, body) {
if ( error || response.statusCode != 200)
return (res.status (response.statusCode).end ()) ;
var data =JSON.parse (body) ;
res.json (data.inkomensvolgenswoonplaatsperdistrict) ;
});
}) ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.