android中如何创建字符串数组对象数组对象,android:创建json对象或数组?

我每天都在学习更多关于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用户,所以不确定质量,但它至少包含路由)。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值