Skip to content

Instantly share code, notes, and snippets.

@skihero
Created March 24, 2011 12:35
Show Gist options
  • Save skihero/884977 to your computer and use it in GitHub Desktop.
Save skihero/884977 to your computer and use it in GitHub Desktop.
ExtractZimbraJsonResponse
package com.org.json;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.*;
import org.json.*;
public class JSONParser {
/* Various request that we have collected from
* the server
*/
private String createRequest ;
private String createResponse;
private String createResponseVerbose ;
private String getRequest ;
private String getResponse ;
private String getResponseVerbose ;
private JSONObject json ;
private String jsonTxt=null ;
JSONParser() throws FileNotFoundException, JSONException{
FileInputStream input = new FileInputStream("json.file");
try {
jsonTxt = IOUtils.toString( input );
System.out.println("text : "+ jsonTxt);
System.out.println("End jsonTxt");
JSONObject json_string = new JSONObject(jsonTxt);
System.out.println("Name: " +json_string.get("name") ) ;
JSONArray jsa = json_string.getJSONArray("a");
JSONObject item = jsa.getJSONObject(0);
String zimbraid = item.getString("_content");
/*
for (int i = 0; i < jsa.length(); i++) {
// Run through the items
JSONObject item = jsa.getJSONObject(i);
String title = item.getString("_content");
}
*/
System.out.println("===========================================================");
System.out.println("Zimbraid "+ zimbraid);
System.out.println("===========================================================");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
JSONParser jp = new JSONParser() ;
}
catch (Exception e){
e.printStackTrace() ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment