JSON delivery of background data issues

Source: Internet
Author: User

I have two classes in the background:

     Public Class Person {      private  String name;       Private Address address; // a custom class       // getter and Setter methods omitted   Public Class  Address {      private String Road;                    //getter and setter method omitted      }  

Logic classes:

@Controller Public classPersonController {@AutowiredPrivatePersonservice Personservice; @RequestMapping (Value="getpersons.htm", method =requestmethod.get) PublicModelandview View () {System. out. println ("Success"); List<Person> persons = Personservice.getpersons ();//Customizing the methodmap<string, object> modelmap =NewHashmap<string, object>(); Modelmap.put ("Persons", persons); return NewModelandview (MODELMAP); }      }  

In JS see the JSON data obtained is this:

{"Persons":[{"Address":{"Road":"Shopping mall"},"name":"Xiao Ming"},{"Address":{"Road":"Lotus Street"},"name":"Little Red"}]}

Front Code:

Ext.onready (function () {varstore =NewExt.data.Store ({proxy:NewExt.data.HttpProxy ({URL:'getpersons.htm'}), Reader:NewExt.data.JsonReader ({root:'Books'}, [{name:'name'}, {name:'Address'                                              }])                          }); varPersons =NewExt.grid.GridPanel ({store:store, CM:NewExt.grid.ColumnModel ({defaults: { Sortable:true, Width: $}, Columns: [{ Header:"name", Dataindex:'name'}, {header: /c8>"Address", Dataindex:'Address'                                                  }]                                      }), Width:430, Height: the, Title:'Test', Renderto:'Persons'                          });              Store.load ();  }); 
    varstr ='[{"Persons": [{"Address": {"Road": "Commercial Street"}, "name": "Xiaoming"},{"address": {"Road": "Lotus Street"}, "name": "Little Red"}]}]'; STR=eval (str);  for(varI=0; i<str.length;i++){                      varstrpersons=str[i].persons;  for(varj=0; j<strpersons.length;j++) {alert (strpersons[j].name);                      alert (strpersons[j].address.road); }                    }   

JSON delivery of background data issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.