Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid characters in json response

I am unable to process the json response ,while accessing the json response I am getting some invalid characters in the json response,so How can we remove white space issues and invalid characters from the json response using php scirpt

My json Response :

[{"keyword":"cosmetic dermatology","svol":4400},{"keyword":"dermatology associates","svol":22200},{"keyword"
:"advanced dermatology","svol":40500},{"keyword":"dermatology clinic","svol":3600},{"keyword":"dermatology
 specialists","svol":3600},{"keyword":"dermatology consultants","svol":5400},{"keyword":"pediatric dermatology"
,"svol":3600},{"keyword":"what is dermatology","svol":1900},{"keyword":"dermatology pictures","svol"
:1300},{"keyword":"dermatological","svol":2400},{"keyword":"laser dermatology","svol":1300},{"keyword"
:"dermatology group","svol":1900},{"keyword":"dermatology uk","svol":390},{"keyword":"dermatology courses"
,"svol":1000},{"keyword":"dermatologic","svol":1600},{"keyword":"westlake dermatology","svol":8100},
{"keyword":"pariser dermatology","svol":3600},{"keyword":"aesthetic dermatology","svol":1000},{"keyword"
:"dermatology doctors","svol":590},{"keyword":"north dallas dermatology","svol":1300} ]

And My JQuery is:

$.ajax({
            type:"post", 
            datatype : 'json',
            url:"GetKeyWordBids.php", 
            data:"specialty="+ spevalue,
            success: function(s) {
                var object = $.parseJSON(s);
                /*oTable.fnClearTable();
                oTable.fnAddData([
                    s
                ]); */
            }
        }); 

FireBug Output:

SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 25230 of the JSON data

And Jsonlint.com output for json response:

Parse error on line 75:
...        "keyword": "ear nose and throat
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
like image 898
Neha Chakradeo Avatar asked Mar 19 '26 11:03

Neha Chakradeo


2 Answers

You don't need to use $.parseJSON(); since datatype : 'json' is specified. the returned data is already in the JSON format just use it directly.

like image 57
Satpal Avatar answered Mar 22 '26 00:03

Satpal


Please paste your JSON data here: http://jsonlint.com/ and see that the JSON syntax is bad.

When you'll fix that, use Satpal answer (don't include $.parseJSON)

like image 41
gididaf Avatar answered Mar 22 '26 01:03

gididaf