I am attempting to extract the raw data from the JSON without including the headers. For example, I want to retrieve '1' but not 'ID', or 'foo' but not 'Name'.
[{ID = 1, Name = "foo", Email = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34525b5b74525b5b1a575b59">[email protected]</a>"},
{ID = 2, Name = "bar", Email = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4969586b4969586da979b99">[email protected]</a>"}]
The rationale behind excluding the headers is due to the dynamic nature of the data. The JSON response may contain varying fields per object in different calls. As seen below, my interface only includes a string because the structure of the data is unpredictable.
Below is the TypeScript code I am using to process 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 transformation should occur
// Currently, this does not function as intended
var dataCarrier = result.toString();
JSON.parse(dataCarrier).forEach(item => {
this.rowData = item.name;
});
});
}
}
interface RowInfo {
rowData: string;
}
How can I extract and pass just the individual pieces of JSON data through to the interface while handling multiple rows within the same object?