androidjson服务器
1. android应用怎么样在服务器端解析从客户端发送过来的json数据
首先是服务器要取到数据,然后就是就在服务端解析json啊。。解析都是一样的撒。。可以自己写方法。也可以用别人的jar包。。
2. android 在服务器端生成json格式数据,在客户端怎么解析
1、生成JSON格式数据,有对应的后台类处理,如果你是做Android开发,后台提供获取数据的接口
2、客户端解决:
java">JSONArrayjsonArr=newJSONArray(json);
for(inti=0;i<jsonArr.length();i++){
JSONObjectjsonObj=jsonArr.getJSONObject(i);
booleanisChild=jsonObj.has("childrenNodes");
AreaBeanbean=newAreaBean(jsonObj.getString("id"),
jsonObj.getString("parentId"),
jsonObj.getString("name"));
mList.add(bean);
if(isChild){
mchildNodesList.add(jsonObj.getString("childrenNodes"));
}else{
mchildNodesList.add(null);
}
}
3. Android Json解析服务器文件
JSONObject aJosnObj;
aJosnObj = new JSONObject(stateJson);
JSONArray arrSpecialtys = aJosnObj.getJSONArray("Stations");
for (int i = 0; i < arrSpecialtys.length(); i++) {
JSONObject aJos = (JSONObject) arrSpecialtys.get(i);
String startingStation = aJos.getString("StartingStation");
String lat = aJos.getString("Lat");
}
String lineNum = aJos.getString("LineNum");
这样就可以把"中国科技大学"、31.8308990633944和24分别存放在startingStation、lat和lineNum中
4. android客户端与服务器发之间的json数据解析
JSONArray jsonArray = new JSONArray(string); //string为返回的字符串
//数据直接为一个数组形式,所以可以直接 用android提供的框架JSONArray读取JSON数据,转换成Array
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
//每条记录又由几个Object对象组成
iitem.getInt("index");
// 获取对象对应的值
item.getString("address");
}
5. Android 解析json问题
///http地址
StringhttpUrl=ip+":"+端口号+"/loginbyandroid/validate.do";
//HttpPost连接对象
HttpPosthttpRequest=newHttpPost(httpUrl);
//使用NameValuePair来保存要传递的Post参数
List<NameValuePair>params=newArrayList<NameValuePair>();
//添加要传递的参数
params.add(newBasicNameValuePair("loginId","value"));
params.add(newBasicNameValuePair("password","value"));
//设置字符集
HttpEntityhttpentity;
try{
httpentity=newUrlEncodedFormEntity(params,"utf-8");
//请求httpRequest
httpRequest.setEntity(httpentity);
//取得默认的HttpClient
HttpClienthttpclient=newDefaultHttpClient();
//取得HttpResponse
HttpResponsehttpResponse;
httpResponse=httpclient.execute(httpRequest);
//HttpStatus.SC_OK表示连接成功
if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
//取得返回的字符串
StringstrResult=EntityUtils.toString(httpResponse
.getEntity());
JSONArrayjsonArray=newJSONArray(strResult);
for(inti=0;i<jsonArray.length();i++){
JSONObjectjsonObject=(JSONObject)jsonArray.opt(i);
Stringsuccess=jsonObject.getString("success");
StringJSESSIONID=jsonObject.getString("JSESSIONID");
StringloginName=jsonObject.getString("loginName");
Stringorgname=jsonObject.getString("orgname");
System.out.println("success="+success
+"JSESSIONID="+JSESSIONID+"loginName="
+loginName+"orgname="+orgname);
}
}else{
System.out.println("请求错误!");
}
}catch(ClientProtocolExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}
6. Android利用Json来进行网络数据传输
有点晕晕的,如果你是传多个对象[{id:1,name:"tom",age:"20"},{id:2,name:"tom",age:"20"}]
怎么搞成服务器请求客户端了??不是客户端请求服务器吗?
一般JSON对应json都是通过id来对应的,我就是这样对应的
7. Android请求php服务器的JSON问题
因为PHP会默认添加一个bom头信息 有几个字节 你得去掉 一般是四个字节
package cn.image.sky.util;
import java.io.*;
/**
* Generic unicode textreader, which will use BOM mark to identify the encoding
* to be used. If BOM is not found then use a given default or system encoding.
*/
public class UnicodeReader extends Reader {
PushbackInputStream internalIn;
InputStreamReader internalIn2 = null;
String defaultEnc;
private static final int BOM_SIZE = 4;
/**
*
* @param in
* inputstream to be read
* @param defaultEnc
* default encoding if stream does not have BOM marker. Give NULL
* to use system-level default.
*/
UnicodeReader(InputStream in, String defaultEnc) {
internalIn = new PushbackInputStream(in, BOM_SIZE);
this.defaultEnc = defaultEnc;
}
public String getDefaultEncoding() {
return defaultEnc;
}
/**
* Get stream encoding or NULL if stream is uninitialized. Call init() or
* read() method to initialize it.
*/
public String getEncoding() {
if (internalIn2 == null)
return null;
return internalIn2.getEncoding();
}
/**
* Read-ahead four bytes and check for BOM marks. Extra bytes are unread
* back to the stream, only BOM bytes are skipped.
*/
protected void init() throws IOException {
if (internalIn2 != null)
return;
String encoding;
byte bom[] = new byte[BOM_SIZE];
int n, unread;
n = internalIn.read(bom, 0, bom.length);
if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00)
&& (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
encoding = "UTF-32BE";
unread = n - 4;
} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)
&& (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
encoding = "UTF-32LE";
unread = n - 4;
} else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB)
&& (bom[2] == (byte) 0xBF)) {
encoding = "UTF-8";
unread = n - 3;
} else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
encoding = "UTF-16BE";
unread = n - 2;
} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
encoding = "UTF-16LE";
unread = n - 2;
} else {
// Unicode BOM mark not found, unread all bytes
encoding = defaultEnc;
unread = n;
}
// System.out.println("read=" + n + ", unread=" + unread);
if (unread > 0)
internalIn.unread(bom, (n - unread), unread);
// Use given encoding
if (encoding == null) {
internalIn2 = new InputStreamReader(internalIn);
} else {
internalIn2 = new InputStreamReader(internalIn, encoding);
}
}
public void close() throws IOException {
init();
internalIn2.close();
}
public int read(char[] cbuf, int off, int len) throws IOException {
init();
return internalIn2.read(cbuf, off, len);
}
}
这个类 你看看 可以解决你的问题
8. 请问android怎样通过json数据从服务器获取图片
直接获取是不行的,要有一个文件服务器,对于文件服务器会为每个图片生成一个资源路径,然后json数据中返回的就是这个资源路径,最后用URL类就可以通过这个资源路径把图片download下来
9. android 中如何在 手机端发送json请求,服务器得到json类型的响应结果
android中要求向服务器发送get,然猴得到响应数据