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

  • SEARCH
  • Home
  • 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 6723597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:35:17+00:00 2026-05-26T09:35:17+00:00

I’m having a problem with getting json data. I created 2 examples. One works,

  • 0

I’m having a problem with getting json data. I created 2 examples. One works, but the other doesn’t. And guess which one I need? Yup, the one that doesn’t work. Here is the code.

I have a web service that outputs json data but for some reason it add extra brackets [] to the string and it’s also missing the single quotes ‘ ‘. If you look at the code that doens’t work, you’ll see that i’m manually removing the brackets and adding the single quotes. I have a div that i write the string to and it’s valid Json data. If I take that string and manually declare a new variable with it, the jQuery.parseJSON works fine. But it I parse the newly created object, it doesn’t work. Anybody have any ideas?

Works Fine

 $.ajax({
    type: "POST",
    async: false,
    contentType: "application/json; charset=utf-8",
    url: "StudiesWebService.asmx/EventList",
    data: "{}",
    dataType: "json",
    success: function(msg) {
        var obj = jQuery.parseJSON('{ "id": 1, "title": "Jack STuff", "start": "\/Date(1318939200000)\/", "end": "\/Date(1318950000000)\/", "allDay": false }, { "id": 2, "title": "asdfasdfasdf", "start": "\/Date(1319025600000)\/", "end": "\/Date(1319025600000)\/", "allDay": false}');
        var events2 = [];
        events2.push({
            title: obj.title,
            allDay: obj.allDay,
            start: 'Tue, 18 Oct 2011 10:00:00 EST',
            end: 'Tue, 18 Oct 2011 11:00:00 EST'
        });

        callback(events2);

    },
    error: function(e) { $(".external-events").html("An Error Occured" + e); }
});

Doesn’t Work:

$.ajax({
    type: "POST",
    async: false,
    contentType: "application/json; charset=utf-8",
    url: "StudiesWebService.asmx/EventList",
    data: "{}",
    dataType: "json",
    success: function(msg) {
        var myObj = new String(msg.d);

        myObj = myObj.replace("[", "");
        myObj = myObj.replace("]", "");
        myObj = "'" + myObj + "'";

        //at this point myObj output to this:
        //'{"id":1,"title":"Mike STuff","start":"\/Date(1318939200000)\/","end":"\/Date(1318950000000)\/","allDay":false},{"id":2,"title":"asdfasdfasdf","start":"\/Date(1319025600000)\/","end":"\/Date(1319025600000)\/","allDay":false}'

        var obj1 = jQuery.parseJSON(myObj);
        alert(obj1.id);  //alert doesn't come up

        var events = [];

        events.push({
            title: obj1.title,
            allDay: obj1.allDay,
            start: 'Tue, 18 Oct 2011 10:00:00 EST',
            end: 'Tue, 18 Oct 2011 11:00:00 EST'
        });

        callback(events);
    },
    error: function(e) { $(".external-events").html("An Error Occured" + e); }
});
  • 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-05-26T09:35:18+00:00Added an answer on May 26, 2026 at 9:35 am

    if you remove this line

    myObj = "'" + myObj + "'";
    

    it should be fine. In the upper example, the '' enclose the string. they are not actually part of the string itself, so they do not need to be added to myObj

    Also, your json has [] around it because it’s actually returning a 2-element array ([{obj1},{obj2}]), so you should either iterate that array, or pull out the first element (obj[0])

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.