我有一个项目要求我构建一个货币转换器,我已经搜索了谷歌并获得了一些可以给我参考的资源,但是当我点击计算时我卡住了它不会将 textview 更改为货币汇率..
我使用 json,这是网站
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDSGD%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
这是一些代码
calculate.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
TextView texts = (TextView) findViewById(R.id.textView3);
try {
s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"+val[from]+val[to]+"%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
JSONObject jObj;
jObj = new JSONObject(s);
String theResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate").getString("Rate");
texts.setText(theResult);
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
val[from]+val[to] 来自我的微调器,我有 2 个微调器
getJson 代码
public String getJson(String url)throws ClientProtocolException, IOException {
StringBuilder build = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String con;
while ((con = reader.readLine()) != null) {
build.append(con);
}
return build.toString();
}
请帮助我..这段代码的错误在哪里我已经尝试编辑并且什么也没得到..仍然当我点击按钮时它没有给我textview的价值