English 中文(简体)
JSON 对象在 Jquery 中解析错误
原标题:JSON object parsing error in Jquery
  • 时间:2012-05-26 09:24:05
  •  标签:
  • jquery
  • json
[
    {
        "regNo": "1",
        "regDate": "2025-05-12",
        "patientName": "Ratna",
        "address": "saasgasgasga",
        "city": "Hyderabad",
        "phno": "2147483647",
        "mrgStatus": "single"
    }
]

从服务器到客户 i m, 使用 < code> jQuery.parseJSON () ethod 来分析数据, 但无效 。 任何人都能帮助我分析吗??

我的代码是这样的...

success:function(data)
{ 
 var myObject = jQuery.parseJSON(data);
 $("#patname").val(myObject.patientName);
 $("#guaname").val(myObject.fathername);
 $("#age").val(myObject.age);
 $("#addr").val(myObject.address);
} 

但此显示为空...

最佳回答

它已经从JSON转换成一个对象 - 你不需要再分析它了。

success:function(data) { 
    $("#patname").val(data[0].patientName);
    $("#guaname").val(data[0].fathername);
    $("#age").val(data[0].age);
    $("#addr").val(data[0].address);
} 
问题回答
    success: function(data) {
     // here data is an array, so you need data[0] to get the object
     $("#patname").val(data[0].patientName);
     $("#guaname").val(data[0].fathername);
     $("#age").val(data[0].age);
     $("#addr").val(data[0].address);
}




相关问题
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 ...

热门标签