What I'm trying to do is extract just the data from the JSON and not the headers(for example, getting 1 but not ID or getting foo and not Name)
[{ID = 1, Name = "foo", Email = "foo@foo.com"},
{ID = 2, Name = "bar", Email = "bar@bar.com"}]
The reason that I just want the data and not the headers is that the data could by dynamic. In one call the JSON returned could have 100 fields per object or 2 fields per object on the next call. Which is why, in the below example, I only have a string in my interface, because I have no clue what kind of data could be passed.
Here is my typescript that I'm trying to get to interpret the data
import { Component } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'fetchdata',
template: require('./fetchdata.component.html')
})
export class FetchDataComponent {
public rowData: RowInfo[];
constructor(http: Http) {
http.get('/api/SampleData/DatatableData').subscribe(result => {
//This is where the magic should happen
//This currently does not work
var dataCarrier = result.toString();
JSON.parse(dataCarrier).forEach(item => {
this.rowData = item.name;
});
});
}
}
interface RowInfo {
rowData: string;
}
How do I go about breaking up the JSON data in the http.get into just its pieces to pass through to the interface while differentiating between the different rows that could be in the same object?