I use the Myeclips Tutorial e tool with the function of import jar, the default this jsonplugin has been imported, so only need to see in MyEclipse, is not already imported this package, if already have, then do not have to import.
Okay, back to the point. Last time we said this was to get a value, what if it was an object? What about a collection?
public class Book
{
Private String BookName;
Private String author;
The getter and setter of these two member variables are omitted here
Public book () {}
Public book (String bookname,string author)
{
This.bookname=bookname;
This.author=author;
}
}
Action Content
public class Testaction extends Actionsupport
{
Private book book;
Private list<book> Booklist;
Public String Execute ()
{
Booklist=new arraylist<book> ();
Book=new book ();
Book.setbookname ("30 days");
Book.setauthor ("Blak");
List.add (New book ("World First, etc", "yes yes");
List.add (new book ("Always Quiet", "Asan"));
List.add (new book ("Struts 2", "Me"));
}
}
<package name= "ajax" extends= "Json-default" >
<actio n name= "Testjson" "class=" action. Testjsonaction ">
<result type=" JSON ">result</result>
</action>
& lt;/package>
page content
<title>testJson</title>
<script type= "Tex xt/Web Effects "src=" Js/jquery.js "></script>
<script type=" texxt/javascript ">
function Testjson () br>{
$.ajax ({
Type: "Post",
URL: "Testjson.action",
data:{},
DataType: "JSON",
Beforesend : function () {},
Success:function (JSON) {
Alert ("Success complete");
Alert ("BookName:" +json.book.bookname+ "Author:" +json.book.author);
var json=eval (json.booklist);
JSON = eval (json.list)
for (var i=0; i<json.length; i++)
{
Alert (json[i].bookname+ "" + json[i].au Thor)
}
}
});
}
</script>
<body>
This are my page!<br/>
<input type= button "value=" Test Ajax "onclick=" Testjson (); "/>
</body>
To access an object, use JSON directly. The name of the field.