0

我就與我的web服務(SOAP)這是我從我如何解析這個結果的web服務收到的XML結果連接,解析XML與KSOAP在android系統

<string>{"30_year_rate":4.250,"30_year_pi":196.78,"30_year_apr":4.375,"QuoteID":1434,"Licensed":"N"}</string> 

有誰能夠告訴我怎麼樣?

非常感謝!

回答

0

那味道像JSON,對不對?如何使用JSONObject解析它:

JSONObject jsonResponse = new JSONObject("..."); 
1

使用下面的代碼片段

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    String readTwitterFeed = readTwitterFeed(); 
    try { 
     JSONArray jsonArray = new JSONArray(readTwitterFeed); 
     Log.i(ParseJSON.class.getName(), 
       "Number of entries " + jsonArray.length()); 
     for (int i = 0; i < jsonArray.length(); i++) { 
      JSONObject jsonObject = jsonArray.getJSONObject(i); 
      Log.i(ParseJSON.class.getName(), jsonObject.getString("text")); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

public String readTwitterFeed() { 
    StringBuilder builder = new StringBuilder(); 
    HttpClient client = new DefaultHttpClient(); 
    HttpGet httpGet = new HttpGet("http://twitter.com/statuses/user_timeline/vogella.json"); 
    try { 
     HttpResponse response = client.execute(httpGet); 
     StatusLine statusLine = response.getStatusLine(); 
     int statusCode = statusLine.getStatusCode(); 
     if (statusCode == 200) { 
      HttpEntity entity = response.getEntity(); 
      InputStream content = entity.getContent(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(content)); 
      String line; 
      while ((line = reader.readLine()) != null) { 
       builder.append(line); 
      } 
     } else { 
      Log.e(ParseJSON.class.toString(), "Failed to download file"); 
     } 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return builder.toString(); 
} 

添加以下權限到你的manifest文件

android.permission.INTERNET