How to parse a JSONArray of JSONObjects in JAVA?


Java_LOGO

In last tutorial we discussed , how to create JSONArray of JSONObjects and pass with Ajax call in JSP.If you want to refer then visit this link:
http://www.jkstack.com/2013/08/how-to-create-json-array-object-with.html

Today,i am going to discussed, how to  parse a JSONArray of JSONObjects in JAVA class.

Here is the code:
package com.actions;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

public class ParseJsonArray {
public void saveValues()
{
try{
String paramJsonValuesString=request.getParameter("paramJsonValues");
JSONObject paramJsonValuesStringJSON=(JSONObject)JSONSerializer.toJSON(paramJsonValuesString);
JSONArray paramPropertyArray=paramJsonValuesStringJSON.getJSONArray("paramProperty");
for(int i=0; i &lt paramPropertyArray.size(); i++)
{
JSONObject jsonObject=paramPropertyArray.getJSONObject(i);
String Id = jsonObject.getString("Id");
String name = jsonObject.getString("name");
String age = jsonObject.getString("age");
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}

Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

5 comments: