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 1103207
In Process

The Archive Base Latest Questions

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

I’m trying to consume a WCF webservice using jQuery. The returned Json data is:

  • 0

I’m trying to consume a WCF webservice using jQuery.
The returned Json data is:

{
    "ListOfPersons":
        "[
            {'Id':1,'FirstName':'Foo','LastName':'Bar'},
            {'Id':2,'FirstName':'Hello','LastName':'World'},
            {'Id':3,'FirstName':'Tanks','LastName':'Giving'},
        ]"
}

These are the functions I’m using in Jquery is:

 var url = 'http://path/to/webservice.svc/ReturnTheList';
    $.getJSON(url, function (data) {
        success: readData(data)
    });

    function readData(data){
        alert(data.ListOfPersons[0].FirstName);
    }

The problem is that the alert doesn’t return anything.

And, If I modify the Json to:

{
    "ListOfPersons":
        [
            {"Id":1,"FirstName":"Foo","LastName":"Bar"},
            {"Id":2,"FirstName":"Hello","LastName":"World"},
            {"Id":3,"FirstName":"Tanks","LastName":"Giving"},
        ]
}

(I replaced the simple quotes by double quotes and removed the double quotes before the [ and after the ]).

So I concluded that it’s a problem with the returned format.
The problem is that I can’t modify this web service .
How can I consume a “bad-formatted” json structure?

Thanks you,

Regards

EDIT:

Here is the Web Service signature:

 [OperationContract]
        [WebInvoke(Method = "GET",
             BodyStyle = WebMessageBodyStyle.WrappedResponse,
             ResponseFormat = WebMessageFormat.Json)]
        string ReturnTheList();
  • 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-17T01:18:26+00:00Added an answer on May 17, 2026 at 1:18 am

    The newer versions of jQuery (since 1.4 I think) will not load invalid JSON at all.

    You have two options—you can write a server-side proxy which calls the web service, parses the invalid JSON and returns it in a valid form, or you can use this function (written by Alex Sexton, not me!):

    jQuery.getInvalidJSON = function(url, data, callback) {
        return jQuery.get(url, data, function(d){
            callback.call(this, (new Function('return (' + d + ')'))());
        }, "text");
    };
    

    This basically does the same thing as Dewfy’s answer: performing an unsafe eval on the JSON string to get a usable object. Make sure you trust the source before using this method, as anything nefarious hidden in the JSON will be executed.

    Edit: I had a bit of time to actually test this and it turns out there was a small mistake in Alex’s function. The JSON string (variable ‘d’) needs to be wrapped in parentheses to be evaluated as an object—I’ve edited the above code accordingly.

    While the above will load JSON that’s not quite strictly valid (missing quotes around property names, single quotes instead of double etc), it does have its limits. The JSON you are working with from this web service is just plain broken.

    It seems to be the double quotes around the array that are causing most of the problems. You can work around this like so:

    jQuery.getInvalidJSON = function(url, data, callback) {
        return jQuery.get(url, data, function(d){
            var cleaned = d.replace(/"\[/g, '[').replace(/\]"/g, ']');
            callback.call(this, (new Function('return (' + cleaned + ')'))());
        }, "text");
    };
    

    And call it like this:

    $.getInvalidJSON(url, null, readData);
    

    This is very hacky though and I’d strongly recommend fixing the web service so it returns proper, valid JSON.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.