Download JSON Lib For J2ME
![JSON Libaray For J2ME JSON Libaray For J2ME](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9WZF6K958hO0Wodqu1PGIqL38-R8p4T2kV9XUngzibsm9XvT1GDS2t2sPftF_pFmjbyIopGB6_Z52q9TOzoVoyB79f0cKUcUvzprr4uIwoyFycX8kchEO3fMtsdTa1wm0C0m6OK6f_q3X/s320/j2me-json-php.gif) |
J2ME - Parse JSON from PHP |
HttpConnection hc = null;
InputStream ic = null;
try {
hc = (HttpConnection) Connector.open("http://localhost/test/json.php");
hc.setRequestMethod("GET");
ic = hc.openInputStream();
int contentLength = (int)hc.getLength();
byte [] b = new byte[contentLength];
ic.read(b);
String response = new String(b);
JSONObject object = new JSONObject(response);
response = object.getString("time");
System.out.println("Time: " + response);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
if (hc != null) {
hc.close();
ic.close();
}
} catch (Exception e) {}
}
json.php
echo json_encode(array("time" => strval(date("H:i:s"))));