我每天都在学习更多关于android开发和json代码的知识。 但现在我被困在这个; 我可以从我的在线数据库中获取我的值并显示它,但是我看到了整个json代码。 我希望看到我希望它展示的部分。android:创建json对象或数组?
这是我的代码,我认为这是很基本的,但我也学习:)
正如你可以看到我正准备从网页的价值,并把它在我的TextView,但我会喜欢把它放在一个JSONObject或JSONArray中,不知道女巫更好。
有人可以帮我一下吗?
随着亲切的问候
public class Bordje extends Activity{
public void onCreate (Bundle savedInstanceState) {
try
{
super.onCreate(savedInstanceState);
setContentView(R.layout.bordje);
//This is out textview element, obtained by id from XML Layout
TextView myListView = (TextView)findViewById(R.id.netResult2);
//Lets connect to the internet
try {
String result = "";
//create new client object
HttpClient httpclient = new DefaultHttpClient();
//now post to the url
HttpPost httppost = new HttpPost("http://www.wvvzondag2.nl/android/leesbordje.php");
//execute url
HttpResponse response = httpclient.execute(httppost);
//get message from the response
HttpEntity entity = response.getEntity();
//get the content from message
InputStream webs = entity.getContent();
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(webs, "iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
//slow our inputstream
webs.close();
//puts the resut into a string
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//Parsing the JSON Data
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i
JSONObject json_data = jArray.getJSONObject(i);
json_data.getString("introtext");
//Get an output to the screen
//then here should be some code that displays text?
//myListView.setText(Html.fromHtml(json_data)); ?
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
}
catch (Exception e)
{
//this is the line of code that sends a real error message to the log
Log.e("ERROR", "ERROR IN CODE: " + e.toString());
}
}
+0
因此,去你的网站给你的整个数据集,你想从那里解析它?你打算使用任何你要解析的数据吗?如果没有,你正在运行成不需要如果数据不应该被曝光(可能的安全风险)2)大量的带宽需求(Web服务器正在推动更多的数据1)暴露数据的问题,并且您的用户需要使用更多数据才能使用它)。 http://federmanscripts.com/2010/12/12/php-routing/可能是你感兴趣的(不是PHP用户,所以不确定质量,但它至少包含路由)。 –