服务器页数和数据json(数据访问页分为)
更新: <time datetime="2022-11-09 19:30">2022-11-09 19:30</time>
本文目录一览:
- json的简单介绍及基本使用
- 服务器端JSON数据或者xml数据如何设置
- 服务器端和客户端进行json数据传输,json是不是也是通过http协议进行字节流传输的?
- 从服务器端获取JSON格式的数据进行解析的问题,求帮助
- 怎么解析从服务器返回的json
json的简单介绍及基本使用
json是对象由键值对组成 jo={key:value,"t":"haha"}这是一个json对象 使用也很简单 json对象.key 可以取到value值如jo.t便可以取到对应的值
服务器端JSON数据或者xml数据如何设置
服务端打印出来字符串,客户端解析 XML可以直接下载,然后解析 JSON就是一个字符串,放在TXT里就行 生成也很容易,PHP用file_put_contents可以生成TXT,json_encode生成JSON
服务器端和客户端进行json数据传输,json是不是也是通过http协议进行字节流传输的?
先看一看json的定义: JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。 可见它只是一种数据格式,可以对其使用任何可行的传输协议。 但一般的网络传输都使用http协议, 这和使用http协议传输视频格式文件,音频的道理是一致的。 json的传输相当于对字符串的传输。 所以: 服务器端和客户端的json数据传输,可以而且最好使用http协议进行字节流传输,但不仅限于http协议。
从服务器端获取JSON格式的数据进行解析的问题,求帮助
我们不返回json格式的字符串到客户端呢然后再用js解析呢json字符串一定的弄个json文件存放吗?
怎么解析从服务器返回的json
json数据格式解析我自己分为两种; 一种是普通的,一种是带有数组形式的; 普通形式的: 服务器端返回的json数据格式如下:
{"userbean":{"Uid":"100196","Showname":"疯狂的猴子","Avtar":null,"State":1}}
分析代码如下:
// TODO 状态处理 500 200
int res = 0;
res = httpClient.execute(httpPost).getStatusLine().getStatusCode();
if (res == 200) {
/*
* 当返回码为200时,做处理
* 得到服务器端返回json数据,并做处理
* */
HttpResponse httpResponse = httpClient.execute(httpPost);
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader2 = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
String str2 = "";
for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2
.readLine()) {
builder.append(s);
}
Log.i("cat", "" + builder.toString());
JSONObject jsonObject = new JSONObject(builder.toString())
.getJSONObject("userbean");
String Uid;
String Showname;
String Avtar;
String State;
Uid = jsonObject.getString("Uid");
Showname = jsonObject.getString("Showname");
Avtar = jsonObject.getString("Avtar");
State = jsonObject.getString("State");
}
带数组形式的: 服务器端返回的数据格式为:
{
"calendar": {
"calendarlist": [
{
"calendar_id": "1705",
"title": "(亲子)ddssd",
"category_name": "默认分类",
"showtime": "1288927800",
"endshowtime": "1288931400",
"allDay": false
},
{
"calendar_id": "1706",
"title": "(旅行)",
"category_name": "默认分类",
"showtime": "1288933200",
"endshowtime": "1288936800",
"allDay": false
}
]
}
}
分析代码如下:
// TODO 状态处理 500 200
int res = 0;
res = httpClient.execute(httpPost).getStatusLine().getStatusCode();
if (res == 200) {
/*
* 当返回码为200时,做处理
* 得到服务器端返回json数据,并做处理
* */
HttpResponse httpResponse = httpClient.execute(httpPost);
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader2 = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
String str2 = "";
for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2
.readLine()) {
builder.append(s);
}
Log.i("cat", "" + builder.toString());
/**
* 这里需要分析服务器回传的json格式数据,
*/
JSONObject jsonObject = new JSONObject(builder.toString())
.getJSONObject("calendar");
JSONArray jsonArray = jsonObject.getJSONArray("calendarlist");
for(int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
CalendarInfo calendarInfo = new CalendarInfo();
calendarInfo.setCalendar_id(jsonObject2.getString("calendar_id"));
calendarInfo.setTitle(jsonObject2.getString("title"));
calendarInfo.setCategory_name(jsonObject2.getString("category_name"));
calendarInfo.setShowtime(jsonObject2.getString("showtime"));
calendarInfo.setEndtime(jsonObject2.getString("endshowtime"));
calendarInfo.setAllDay(jsonObject2.getBoolean("allDay"));
calendarInfos.add(calendarInfo);
}
}
总结,普通形式的只需用JSONObject
,带数组形式的需要使用JSONArray
将其变成一个list。