2016-04-14 120 views
-1

我使用JSON从网上完美接收数据,但我想使用我存储在数据库中的经度和纬度,然后想要在MapActivty中使用,所以我想将所有值存储在一个简单的数组中在MapActivity中玩它如何将JSON值存储到数组

ServiceHandler serviceClient = new ServiceHandler(); 
       Log.d("url: ", "> " + URL_ITEMS); 
       String json = serviceClient.makeServiceCall(URL_ITEMS,ServiceHandler.GET); 
       // print the json response in the log 
       Log.d("Get match fixture resps","> " + json); 
       if (json != null) { 
        try { 
         Log.d("try", "in the try"); 
         JSONObject jsonObj = new JSONObject(json); 
         Log.d("jsonObject", "new json Object"); 
         // Getting JSON Array node 
         matchFixture = jsonObj.getJSONArray(TAG_FIXTURE); 
         Log.d("json aray", "user point array"); 
         int len = matchFixture.length(); 
         Log.d("len", "get array length"); 
         for (int i = 0; i < matchFixture.length(); i++) { 
          JSONObject c = matchFixture.getJSONObject(i); 
          String matchId = c.getString(TAG_MATCHID); 
          Log.d("matchId", matchId); 
          String teamA = c.getString(TAG_TEAMA); 
          Log.d("teamA", teamA); 
          String teamB = c.getString(TAG_TEAMB); 
          Log.d("teamB", teamB);` 
+0

你能否提供你的JSON结构样本? –

回答

0

我建议使用GSON或杰克逊转换回来和从Java/JSON。

GSON - 基于现有的答案

Gson - convert from Json to a typed ArrayList<T>

arrayFromJson = gson.fromJson(json, new TypeToken<List<Pair<Float,Float>>(){}.getType()); 

谷歌地图API具有经纬度对象是一对,所以你可能想尝试。

for (LatLng latlng: arrayFromJSON) { 

    Marker marker = mMap.addMarker(new MarkerOptions() 
         .position(latlng) 
         .draggable(true)); 
} 

你可能想看看:

arrayFromJson = gson.fromJson(json, new TypeToken<List<LatLng>(){}.getType()); 

然后你可以用添加标记Google Maps Example看到这一切是如何一起工作。

+0

我得到了数组中的数据先生我怎么能发送这个数据到MapActivity –

+0

我添加了一些更多的信息给答案 –