Last active
August 29, 2015 14:15
-
-
Save uttesh/4e7b5ff42b8f49074185 to your computer and use it in GitHub Desktop.
Generate/Read the Json string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
/** | |
* | |
* @author Rivet Systems | |
*/ | |
public class JsonStringGenerate { | |
public static void main(String[] args) { | |
JSONObject json = new JSONObject(); | |
List<JSONObject> addresses = new ArrayList<JSONObject>(); | |
JSONObject address; | |
try { | |
int count = 15; | |
for (int i = 0; i < count; i++) { | |
address = new JSONObject(); | |
address.put("CustomerName", "\\u52d5 Uttesh" + i); | |
address.put("AccountId", "1999" + i); | |
address.put("SiteId", "1888" + i); | |
address.put("Number", "7" + i); | |
address.put("Building", "Rivet" + i); | |
address.put("Street", "Sadashiv" + i); | |
address.put("City", "Banglaore" + i); | |
address.put("ZipCode", "ZZ00 XX1" + i); | |
address.put("Country", "India" + i); | |
addresses.add(address); | |
} | |
json.put("Addresses", addresses); | |
} catch (JSONException ex) { | |
Logger.getLogger(JsonStringGenerate.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
String myjsonString = json.toString(); | |
System.out.println("JSON Response :"+myjsonString); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import org.codehaus.jackson.map.ObjectMapper; | |
import org.codehaus.jackson.type.TypeReference; | |
import org.json.JSONObject; | |
/** | |
* | |
* @author Rivet Systems | |
*/ | |
public class JSONReader { | |
public static void main(String[] args) { | |
String json = "{\"name\":\"Uttesh\", \"blog\":\"uttesh.blogspot.com\"}"; | |
try { | |
JSONObject _json = new JSONObject(json); | |
System.out.println("_json ; "+_json); | |
System.out.println(_json.get("name")); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment