Skip to content

Instantly share code, notes, and snippets.

@manishkpr
Created December 30, 2016 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manishkpr/9f566c53bc2cc3ae9e787d6f31e2348f to your computer and use it in GitHub Desktop.
Save manishkpr/9f566c53bc2cc3ae9e787d6f31e2348f to your computer and use it in GitHub Desktop.
package com.manishkpr.autotextviewexample;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
public class JsonParse {
double current_latitude,current_longitude;
public JsonParse(){}
public JsonParse(double current_latitude,double current_longitude){
this.current_latitude=current_latitude;
this.current_longitude=current_longitude;
}
public List<SuggestGetSet> getParseJsonWCF(String sName)
{
List<SuggestGetSet> ListData = new ArrayList<SuggestGetSet>();
try {
String temp=sName.replace(" ", "%20");
URL js = new URL("http://webheavens.com/suggestion.php?name="+temp);
URLConnection jc = js.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
JSONObject jsonResponse = new JSONObject(line);
JSONArray jsonArray = jsonResponse.getJSONArray("results");
for(int i = 0; i < jsonArray.length(); i++){
JSONObject r = jsonArray.getJSONObject(i);
ListData.add(new SuggestGetSet(r.getString("id"),r.getString("name")));
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return ListData;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment