Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:33:29+00:00 2026-06-16T03:33:29+00:00

I have JSON coming from my server into my javascript like so – <script>

  • 0

I have JSON coming from my server into my javascript like so –

<script>
   var resp = <?php  echo getjsonFromServer() . ';'?> 
   resp=JSON.parse(resp);
   displayStats(resp);
</script>

This yields an error ‘SyntaxError: Unexpected token o’ and when I check the console I see that the response has already been JSON parsed . Meaning I shouldn’t have tried to JSON.parse an already parsed answer .

My question is – how come ? Who parsed my JSON for me ? I’m used to call JSON.parse whenever I get JSON from the server , e.g ajax calls . Why is it not the same here ?

Note – My PHP is something like this

header('"Content-Type":application/json');
$js = json_encode($js);
echo $js;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:33:29+00:00Added an answer on June 16, 2026 at 3:33 am

    Look at your generated source.

    You’re echoing raw JSON, so your source looks like

    var resp = { "property": "value", ... };
    

    That’s an object literal, not a string

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model coming from the server as json like this {
I have determined that my JSON, coming from the server, is valid (making the
I have my json value coming from java, as var obj = [{id:58,str:sd <p/>
Issue : I have Json coming back from the server. The Json is an
I have a JSON array coming in from the server with an array of
I have the following JSON coming back from a web service which I am
Here is the two scripts I have Script 1: <? include('config.php'); $json = $_POST['payload'];
I have the following JSON string coming from external input source: {value: "82363549923gnyh49c9djl239pjm01223", id:
I have a function like this: $.getJSON('<?php echo site_url('get_leads/main_contact'); ?>', function(data) { ... });
I have a JSON response that I turn into a Dictionary like so: NSError

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.