如何在blackberry+;JAVA

如何在blackberry+;JAVA,java,json,blackberry,Java,Json,Blackberry,我正在获取json对象,我想从json获取格式化的地址值,我将如何获取 您可以在点击此服务器时检查json值 private void getLocationFromGoogleMaps() { try { StreamConnection s = null; InputStream iStream = null;

我正在获取json对象,我想从json获取格式化的地址值,我将如何获取

您可以在点击此服务器时检查json值

   private void getLocationFromGoogleMaps() {
                        try {
                            StreamConnection s = null;
                            InputStream iStream = null;     
                            long lat=(long) 28.04;
                            long longt=(long) 77.0484;
                            s=(StreamConnection)javax.microedition.io.Connector.open("http://maps.googleapis.com/maps/api/geocode/json?latlng=28.6353080,77.2249600&sensor=true");//&deviceside=false&ConnectionType=mds-public"

                            HttpConnection con = (HttpConnection)s; 
                            con.setRequestMethod(HttpConnection.GET);
                            con.setRequestProperty("Content-Type", "//text");
                             int status = con.getResponseCode();
                             if (status == HttpConnection.HTTP_OK)
                             {
                                 iStream=s.openInputStream();                    
                                 int len=(int) con.getLength();
                                 byte[] data = new byte[8000];                    
                                 byte k;
                                 String result="";
                                 while((k = (byte)iStream.read()) != -1) {
                                     result = result+(char)k;
                                 }  

                                // System.out.println("------0-----------------------+result"+result);
                                 try {
                                      JSONObject jsonObjectMapData=new JSONObject(result);   
                                      System.out.println("-------nav--------"+jsonObjectMapData.getJSONArray("formatted_address"));
                                      synchronized(Application.getEventLock())
                                      {
                                    Dialog.alert("------------------------"+jsonObjectMapData.getJSONObject("formatted_address"));
                                      }
                                      //lblLoc.setText("Location information currently unavilable");
        //                           JSONArray  jsonaryPlaceMark = jsonObjectMapData.getJSONArray("Placemark");
        //                          JSONObject address= jsonaryPlaceMark.getJSONObject(0);
        //                           String placeName=address.getString("address");
        //                           if(placeName!=null)
        //                               lblLoc.setText(address.getString("address"));
        //                           else
        //                               lblLoc.setText("Location information currently unavilable");
                                 } catch (Exception e) {
                                     lblLoc.setText("location information Currently Unavilable");
                                 }
                             }
                        }catch (Exception e) {
                            System.out.println(e);
                            lblLoc.setText("location information Currently Unavilable");
                        }        
                    }

用此代码替换try块

JSONObject jsonObjectMapData=new JSONObject(result);
JSONArray arr=jsonObjectMapData.getJSONArray("results");
int size=arr.length();
JSONObject objectArray[]=new JSONObject[size];//this will store all the json object from array
String formatted_address[]=new String[size];//Declare a String array which will store the value of formatted_address
for(int i=0;i<size;i++)
{
objectArray[i]=arr.getJSONObject(i);//now you have objectArray which contains all the object 
 formatted_address[i]=objectArray[i].getString("formatted_address");//Now formated_address string array will store all .Do what you have to do
}
JSONObject jsonObjectMapData=新的JSONObject(结果);
JSONArray arr=jsonObjectMapData.getJSONArray(“结果”);
int size=arr.length();
JSONObject objectArray[]=新JSONObject[size]//这将存储数组中的所有json对象
字符串格式的_地址[]=新字符串[大小]//声明一个字符串数组,该数组将存储格式化的\u地址的值
对于(int i=0;i