English 中文(简体)
j Query.parseJSON - Chrome和Sato自动教化
原标题:jQuery.parseJSON - Chrome and Safari automatically parsing JSON
  • 时间:2011-06-21 05:39:37
  •  标签:
  • jquery
  • json

以下职能导致对 response和Sharma的回复变数无效,但并非是>。

function updatePage(response){ // This argument differs by browser

    response = jQuery.parseJSON(response);

    for(var i=0; i<response.length; i++){
        // conduct magic
    };

};

错误:

Uncaught Type错误: Cannot read property  length  of null

这是因为,除一名JSON(string的回报外,喂养 j。 在没有明确要求的情况下,这似乎是 Chrome和Sato自动教区。 如果在试图将“反应”论点与“贱民”混为一谈之前,我就在“ Chrome”和“Sato”两处打了一名JSON物体。 然而,在德国,它仍是一个扼杀。

在浏览器中处理这一解决办法的唯一解决办法是,确定“反应”是否通过检查其施工者而得到平分:

function updatePage(response){

    if(response.constructor === String){
        response = jQuery.parseJSON(response);
    };

    for(var i=0; i<response.length; i++){
        // conduct magic
    };

};

Am I missing something or is this the only way to handle this currently? Seems like jQuery.parseJSON would detect the user-agent and just return the argument as-is in the case of Chrome/Safari.

<>Pertinent information

  • This is jQuery 1.6.1
  • The response Content-Type from the server is application/json
  • The response argument is originating from your standard jQuery AJAX call:

$.ajax({
    url: API_URL + queryString +  &limit=  + limit,
    type:  GET ,
    cache: false,
    context: document.body,
    success: updatePage,
    error: function(err){
        console.log( ERROR:   + err);
    }
});
最佳回答

它不是“ Chrome”或“Sato”,如果它看到适当的<条码>,它就会 s。 (最新:Content-Type, 您在提问中加入为正确之举) 我可以立即看到为什么不这样做。

您可在以下网址上签字:http://api.jquery.com/jQuery.ajax/>。 www.un.org/spanish/ga/president 然后,您将登上<代码>parseJSON,response<>/code>,这本已是空化物体。

问题回答

暂无回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...