- Java --- use jsonarray
- Public modelandview ajaxtest (httpservletrequest request,
- Httpservletresponse response) throws exception {
- Response. setcharacterencoding ("UTF-8 ");
- String data = request. getparameter ("data ");
- Log.info (">>>>>>>> DATA =" + data );
- Try {
- Jsonobject jsonobj = new jsonobject (data );
- Jsonarray jarr = (jsonarray) jsonobj. Get ("data ");
- For (INT I = 0; I <jarr. Length (); I ++ ){
- Jsonobject jobj = (jsonobject) jarr. Get (I );
- String name = NULL;
- String value = NULL;
- Try {
- Name = (string) jobj. Get ("name ");
- Value = (string) jobj. Get ("value ");
- Log.info (">>>>" + name + "=" + value );
- } Catch (exception Jex ){}
- }
- Response. getwriter (). Write ("{success: True, Info: '" +
- Stringescapeutils. escapejavascript ("saved successfully! ") + "'}");
- } Catch (exception e ){
- Response. getwriter (). Write ("{success: false, Info: '" +
- Stringescapeutils. escapejavascript (E. getmessage () + "'}");
- }
- Return NULL;
- }
Related conversions:
Public static jsonarray getjsonarrayfromresource (context, int resourceid)
Throws jsonexception, ioexception
{
Inputstream is = context. getresources (). openrawresource (resourceid );
Return new jsonarray (utility. getstringfrominputstream (is ));
}
Public static jsonobject getjsonobjectfromresource (context, int resourceid) throws jsonexception, ioexception {
Inputstream is = context. getresources (). openrawresource (resourceid );
Return new jsonobject (utility. getstringfrominputstream (is ));
}
Public static jsonarray getjsonarrayfromstring (string jsonarraystring) throws jsonexception {
Return new jsonarray (jsonarraystring );
}
Public static jsonobject getjsonobjectfromstring (string jsonstring) throws jsonexception
{
Return new jsonobject (jsonstring );
}