# Cannot parse JSON in response

**URL:** <https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743>\
**Category:** ionic-v3\
**Created:** [August 30, 2017, 3:27pm UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743 "2017-08-30T15:27:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 30, 2017, 3:27pm UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/1 "2017-08-30T15:27:52Z")

</div>

Problem State: I calling post request using javaScript and in response i am expecting array of dictionary in JSON Format. here is my code.

```auto
let jsonData = JSON.stringify(params)
return this.http.post(this.baseUrl, jsonData , this.options)
.map(res => res.json()) 
.subscribe( data => {

    console.log(data);
    if (data != null){
      this.data = data

    }else{
      console.log(' Data is null')
    }
  },

   () => console.log('Call Complete')

 );

```

I also tried this piece of code too.

```auto
    return this.http.get(this.baseUrl).map(res => res.json()[0]).subscribe(data => {
      this.data = data.data.children;
      console.log('response received');
      console.log(this.data);
  });

```

Can anyone find where is problem

---

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [August 30, 2017, 4:00pm UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/2 "2017-08-30T16:00:41Z")

</div>

What is your expected output and what are you getting?  
And what is the error?

---

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 31, 2017, 3:44am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/3 "2017-08-31T03:44:20Z")

</div>

data sent to server successfully but i get this error: Response with status: 0 for url: null

![25 PM](https://global.discourse-cdn.com/ionicframework/original/3X/1/6/16c898055d90f8aa9dd37acc35326edc7f897cd0.png)

i am expecting : array of dictionary in json form

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 31, 2017, 3:51am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/4 "2017-08-31T03:51:29Z")

</div>

> [@zahidshabbir92](#):
>
> Can anyone find where is problem

Where does this code live?

---

<div class="post-metadata">

**Author:** ![Arulmano](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arulmano/32/107323_2.png) [@Arulmano](https://forum.ionicframework.com/u/Arulmano)\
**Post date:** [August 31, 2017, 4:08am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/5 "2017-08-31T04:08:42Z")

</div>

remove your which platform did you use. then try to run your project and see your output.

---

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 31, 2017, 4:21am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/6 "2017-08-31T04:21:12Z")

</div>

i am using ios platform

---

<div class="post-metadata">

**Author:** ![Arulmano](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arulmano/32/107323_2.png) [@Arulmano](https://forum.ionicframework.com/u/Arulmano)\
**Post date:** [August 31, 2017, 4:22am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/7 "2017-08-31T04:22:40Z")

</div>

please remove it and re add ios platform. this is an one way solution

---

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 31, 2017, 4:36am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/8 "2017-08-31T04:36:15Z")

</div>

i write this code in provider.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 31, 2017, 4:38am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/9 "2017-08-31T04:38:59Z")

</div>

Then I think subscribing there is a mistake. Providers should return `Observable`s, possibly transformed, but should leave the subscribing to pages.

---

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [August 31, 2017, 6:14am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/10 "2017-08-31T06:14:12Z")

</div>

> [@zahidshabbir92](#):
>
> data sent to server successfully but i get this error: Response with status: 0 for url: null
> 
> i am expecting : array of dictionary in json form

I hope here you are using http.get not http.post

---

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 31, 2017, 7:24am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/11 "2017-08-31T07:24:07Z")

</div>

I tried this l already but no luck until now

```auto
this.myheader = new Headers({
    'Access-Control-Allow-Origin' : '*',
    'Access-Control-Allow-Headers': '*',
    'Content-Type': 'application/json',
    'Accept': 'application/json; charset=utf-8',
    'Access-Control-Allow-Methods' : 'POST, GET, DELETE, OPTIONS, PUT',

  });
  this.options = new RequestOptions({ headers: this.myheader });

return this.http.get(this.baseUrl).map(res => res.json()).subscribe(data => {
      console.log(data);
  });

```

i get this error

 ![20 PM](https://global.discourse-cdn.com/ionicframework/original/3X/6/f/6f728ab911bcc1061a01ed739769759e401d3de8.png)

---

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [August 31, 2017, 7:48am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/12 "2017-08-31T07:48:58Z")

</div>

@zahidshabbir92

is `this.baseUrl` a php file?  
then add `header('Access-Control-Allow-Origin: *');` on top in the PHP page.

Also run the url direcly on the browser(Firefox preferably) and see what you get?

---

<div class="post-metadata">

**Author:** ![zahidshabbir92](https://avatars.discourse-cdn.com/v4/letter/z/f17d59/32.png) [@zahidshabbir92](https://forum.ionicframework.com/u/zahidshabbir92)\
**Post date:** [August 31, 2017, 7:54am UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/13 "2017-08-31T07:54:18Z")

</div>

if hit this url `this.baseUrl` directly it return response correctly.

---

<div class="post-metadata">

**Author:** ![arnoldparge](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arnoldparge/32/111355_2.png) [@arnoldparge](https://forum.ionicframework.com/u/arnoldparge)\
**Post date:** [August 31, 2017, 1:16pm UTC](https://forum.ionicframework.com/t/cannot-parse-json-in-response/103743/14 "2017-08-31T13:16:55Z")

</div>

> [@arnoldparge](#):
>
> is this.baseUrl a php file?
> 
> then add header(‘Access-Control-Allow-Origin: \*’); on top in the PHP page.

what about this? did you try this?
