0

I am new to JSON. I am trying to retrieve JSON data from a file using the below code.

$.getJSON("test1.json",function(data){

The data in file is as mentioned below:

{
    "Ad": [
        {
            "ImpUrl": "http:\/\/test.com\/18148682\/385490696\/?_RM_HTML_CALLBACK_=callbackFunction",
            "ClkUrl": "http:\/\/test.com\/HomeLending_TDB_HP_B_EN_b000-00-647.html\/446f783068314a6e3232674144484e69?_RM_HTML_CALLBACK_=callbackFunction",
            "FileUrl": "http:\/\/test.com\/385490696\/?_RM_HTML_CALLBACK_=callbackFunction",
            "Text": " \r\n\r\n \"Great\r\n <\/div> \r\n\r\n\r\n\r\n\r\n\r\n\r\n Great rates, legendary service.\r\n <\/h5>\r\n\r\n\r\n \r\n\r\n <\/a>\r\n A mortgage with all the comforts of home.\r\n <\/li>\r\n \r\n <\/ul>\r\n \r\n Calculate your rates and payment<\/span><\/a>\r\n\r\n \r\n\r\n > Buying a Home? <\/a>
            \r\n \r\n> Refinancing?<\/a>\r\n <\/p>\r\n <\/div>\r\n<\/div>",
        }
    ]
}

When I remove all the "\" and "\n\r" from the data it starts going inside the function, but with these it does not.

Thanks,
-Ritesh

eyquem
  • 26,771
  • 7
  • 38
  • 46
Ritesh
  • 1,053
  • 5
  • 16
  • 29
  • What is your question? – vipw Oct 24 '13 at 10:32
  • See http://stackoverflow.com/questions/395379/problem-when-retrieving-text-in-json-format-containing-line-breaks-with-jquery – erKURITA Oct 24 '13 at 10:37
  • My question is if I receive this kind of data from a server, what to do so that it goes inside the function mentioned above. – Ritesh Oct 24 '13 at 10:37
  • I saw the post before I posted my question. In the other post the guy is uploading the JSON data so he can encode escape sequences. In my case I am a consumer and this data is coming from a server. – Ritesh Oct 24 '13 at 10:42
  • Is there really a hard newline within the `Text` property value? This is not allowed in JSON, all newlines need to be represented as `\n` (or `\r\n`). – Ian Roberts Oct 24 '13 at 10:53
  • @IanRoberts Unfortunalety,This is the response I am getting in JSON response. – Ritesh Oct 24 '13 at 11:34
  • Then it's not JSON. It might look a bit like JSON but it's not valid, and it's the _server_ that needs to be fixed to send valid responses. – Ian Roberts Oct 24 '13 at 13:00

1 Answers1

0

Ritesh Your JSON data is not well formated, Check " closing and ending. I see there is an extra quote near "Great.

Praveen Govind
  • 2,619
  • 2
  • 32
  • 45