Iterate JSON

Hello everybody, I’m following this guide but I get errors like “NgFor can’t iterate [object object]”.
How to iterate a json object like this?

thanks in advance


I think you’re trying to iterate over the literal string of ‘[object object]’, meaning that you’re not parsing the JSON object right.

Make the map() function multi-line, and add a breakpoint after you call .json() to parse the response. See what resJson is set to and that should give you an idea of how to properly map your API. My guess is that it’ll be something like this:

      .map(res => {
           let resJson  = res.json();
           console.log("PARSED OBJECT: " + resJson);
           return resJson.value.results; // this is just my guess, verify in debugger
      .subscribe(results => {
           this.results = results; // "results" should be an array of results

Thanks for your answer @jvall, but does not resolve this issue.
Using your solution I get “EXCEPTION: resJson.value is undefined”.

Changing return resJson.value.results to return resJson.results gives me the right series of [object Object], but stil can’t parse.

(I tried with I get 5*[object Object])

Any other hint?

Edit: Json structure, I have to access all the lists in “results” array
“results”: [
“gender”: “female”,
“name”: {
“title”: “ms”,
“first”: “alexis”,
“last”: “lee”
“location”: {
“street”: “1603 opoho road”,
“city”: “wellington”,
“state”: “tasman”,
“postcode”: 57105

“n-key”: “value”
{…}, <------------------- 2nd RANDOM USER

{…}, <------------------- Nth RANDOM USER
“info”: { <----------------------- Don’t need this
"seed": “e65d4bad076516d3”,
“results”: N,
“page”: 1,
“version”: “1.1”

(How to render indentation?)

EDIT 2: Found a solution, I will provide code as soon as possible

So this is my proposition. I think that you have a provider, so in your provider you can put this code:

getRemoteData() {
.map(res => res.json())
.subscribe( data => {
this.users = data;