Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am struggling to parse JSON data. I am calling a webmethod to get JSON data in form of string.
here is the sample.
{
    "data": [
        {
            "act": "8.6",
            "dt": "01-Feb-2004"
        },
        {
            "act": "4.9",
            "dt": "01-Mar-2004"
        },
        {
            "act": "7.3",
            "dt": "01-Apr-2004"
        },
        {
            "act": "6.8",
            "dt": "01-May-2004"
        },
        {
            "act": "8.1",
            "dt": "01-Jun-2004"
        }
    ]
}


This is how I am trying to parse it.
$.ajax({
         type: "POST",
         url: "testJSON.aspx/getHistory",
         data: "{}",
         contentType: "application/json",
         dataType: 'json',
         success: function (data) {
         alert('Into the function');
         var obj = JSON.parse(data);
         }
      });


I found
SyntaxError: JSON.parse: unexpected character
error while debugging in firebug. I have checked my JSON on http://jsonlint.com/[^] and its seems to be fine.

Anyone can point out mistake. I must doing something silly out here. Please give me the solution.
Posted
Comments
Reshma Babu 7-Jan-14 1:52am    
This may be due browser issue. JSON.Parse() is supported by IE 8+ versions. You can use json2.js instead.
You can refer:
Parse Json
comred 7-Jan-14 2:01am    
I am using FireFox ver 26.0
Reshma Babu 7-Jan-14 3:34am    
You can try with eval().

var parsedJSON = eval('('+data+')');
Member 10507756 7-Jan-14 2:11am    
Try using data: JSON.stringify(jason object)
comred 7-Jan-14 2:17am    
It will converts Java script data into JSON right. whereas I am having JSON data string. All I need it is JSON object in form of array. And for that I need to parse it i guess.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900