String s = "http://www.testandroid.com/getfiles";
URL urls;
try {
urls = new URL(s);
URLConnection tc = urls.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
//JSON dan gelen ifade array ise bu sekilde kullanilir
JSONArray ja = new JSONArray(line);
for (int i = 0; i < ja.length(); i++) {
JSONObject c = ja.getJSONObject(i);
String fileName = c.getString("FileName");
String fileDate = c.getString("FileDate");
Dosya doc = new Dosya(fileName, fileDate);
flList.add(doc);
}
// JSON dan tek bir satır geliyorsa kullanım şekli aşağıdaki gibidir.
JSONObject c =new JSONObject("columnName");
}
}
catch (Exception e) {
}
Mary
05/12/2012 — 23:22
cuttle sagt:Hi jogep, thanks for your reply.My error codes are as foonlwilg:-private String filters;public void setFilters(String filters) {this.filters = filters;} . .public String execute() throws Exception {if (this.filters != null) {System.out.println( filters = + this.filters);jsonFilter = (JSONObject) JSONSerializer.toJSON(this.filters); //< (the codes below this line never run.)System.out.println("after Json 1");groupOp = jsonFilter.getString("groupOp");System.out.println("groupOp :" + groupOp);rules = jsonFilter.getJSONArray("rules");rulesCount = JSONArray.getDimensions(rules)[0];System.out.println("rulesCount = " + rulesCount);}System.out.println("after Json 2");return SUCCESS;}The filter String is: {"groupOp":"AND","rules":[{"field":"remark","op":"bw","data":"test"}]}Thank you!
Emrah Kahraman
06/12/2012 — 08:36
List params = new ArrayList ();
JSONArray rules = null;
JSONObject json = jsonParser.makeHttpRequest(“http://www.emrahkahraman.com.tr/mary.json”, “GET”,
params);
try {
rules = json.getJSONArray(“rules”);
int rulesCount=rules.length();
String groupOp = json.getString(“groupOp”);
for (int i = 0; i < rules.length(); i++) { JSONObject c = rules.getJSONObject(i); String field = c.getString("field"); String op = c.getString("op"); String data = c.getString("data"); }
Emrah Kahraman
06/12/2012 — 08:43
JSONArray rules = null;
String filters=”{\”groupOp\”:\”AND\”,\”rules\”:[{\”field\”:\”remark\”,\”op\”:\”bw\”,\”data\”:\”test\”}]}”;
JSONObject json = null;
try {
json = new JSONObject(filters);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
rules = json.getJSONArray(“rules”);
int rulesCount=rules.length();
String groupOp = json.getString(“groupOp”);
for (int i = 0; i < rules.length(); i++) { JSONObject c = rules.getJSONObject(i); String field = c.getString("field"); String op = c.getString("op"); String data = c.getString("data"); }