0
私はアンドロイドに新しいです、私はURLからjsonファイルを読み込もうとしています、そして緯度と長さを取得して マーカーに値をassineし、マップに表示してください、私の質問lan、 jsonの内容を読む?ここ は、JSONのURLデータは、長い間、私は緯度を取得したいアンドロイドでのURLの JSONデータJsonのURLからLan、Longを読み取り、マップのマーカーにlatとlongを割り当てますか?
{"properties":{"1":{"name":"Villa For
Sale","lat":"35.2474962142","lng":"-91.3480163353","price":"$100,000","image1":"http:\/\/wpl28.realtyna.com\/theme28\/wp-content\/uploads\/WPL\/91\/thimg_12_800x420.jpg","image2":"http:\/\/wpl28.realtyna.com\/theme28\/wp-content\/uploads\/WPL\/85\/thimg_2_800x420.jpg"},"2":{"name":"Apartment For Rent","lat":"35.9542249162","lng":"-101.21893164","price":"$40,000","image1":"ht
で、文字列の応答を取得した後、市場 マップ
//this method should get json data from onPostExecute(String s)
public void the_received_data(String received_data){
}
class Read_JSON extends AsyncTask<String ,String ,String >{
MainActivity mainActivity;
// class to handle reading json file
@Override
protected String doInBackground(String... params) {
HttpURLConnection connection =null;
BufferedReader data =null;
InputStream json_data;
try {
URL url = new URL(params[0]);
connection =(HttpURLConnection)url.openConnection();
connection.connect();
//holding the data into stream
json_data =connection.getInputStream();
data = new BufferedReader(new InputStreamReader(json_data));
StringBuffer stringBuffer = new StringBuffer();
//read the data from the bufferedredaer line by line
String line ="";
while((line =data.readLine()) != null){
stringBuffer.append(line);
}
return stringBuffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
if(connection !=null){connection.disconnect();}
try {
if(data != null){
data.close();}
} catch (IOException e) {
e.printStackTrace();
}
}
return null; }
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
mainActivity.the_received_data(s);
}
}