I am getting the following JSON from the restful provider I built to talk to my API server. Im usign Ionic 3…
{
“OCIReturn”: {
“@attributes”: {
“protocol”: “OCI”
},
“sessionId”: “9c94be6c9c3f5b99f01f04df09941659”,
“command”: {
“@attributes”: {
“echo”: “”
},
“defaultDomain”: “clt01.acndigital.net”,
“userLimit”: “4”,
“userCount”: “1”,
“groupName”: “ACN NetEng”,
“callingLineIdName”: “ACN Provisioning”,
“timeZone”: “America/New_York”,
“timeZoneDisplayName”: “(GMT-05:00) (US) Eastern Time”
}
}
}
However when I print the different values to the console.log using standard iterative fashion it works. Why in the consle.log but not in the HTML? Whats the best way to deal with this?
users: Users = ;
constructor(public navCtrl: NavController, public restProvider: BwrestProvider) {
this.getUsers();
}
why can I print out the Properties in the normal fashion inside the console.log statement but when I try to do so in HTML it doesn’t work. I assume I have to convert the Object to an Array but cant get that working correctly.
I get this…
Uncaught (in promise): SyntaxError: Unexpected token o in JSON at position 1 SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse () at http://localhost:8100/build/main.js:107:32 at t.invoke
Im thinking I might have to go back to my provider code and make a change there and not just in my about.ts? Here is my provider code.
constructor(public http: HttpClient) {
console.log(‘Hello RestProvider Provider’);
}
getUsers() {
return new Promise(resolve => {
this.http.get(this.apiUrl, {
headers: new HttpHeaders().set(‘X-DreamFactory-Api-Key’, ‘ABCDEFG…’),
I tried using JSON Stringify as well as the Pipe and it did not work for me. My issue seems to be that I have nested arrays inside my object and I still can not get into the @attributes data.
Notice in the Console when I print
Notice the console log confirm its an object and then also noticed how there is an OCIReturn=>@attributes as well as command=>@attributes. I need the data inside command=>@attribute so ngFor can iterate over it.
However if I return data.OCIReturn as opposed to just data i get the error "can not stat ‘command’…
I think I may
have to go back to HTTPInterceptors ???
I can’t see any array into “command” attribute to iterate with a ngFor. Is it posible that you want get and print all attributes inside “command” attribute like a list?
Because if you want to do that. You can try getting all keys inside “command” attribute by using Object.keys(obj). It returns an Array with all keys inside an object. The you can use those keys to iterate and do anything that you want.
Anyway, your problem seems to be lack knowledge instead an Ionic’s issue.