當前位置:首頁 » 安卓系統 » androidjson伺服器

androidjson伺服器

發布時間: 2022-06-03 07:59:29

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,然猴得到響應數據

熱點內容
離線語音識別android 發布:2025-05-20 08:11:37 瀏覽:152
小鳥雲如何去看客戶伺服器密碼 發布:2025-05-20 07:58:51 瀏覽:898
怎麼更改app的密碼 發布:2025-05-20 07:54:32 瀏覽:784
汽車配置物品怎麼處理 發布:2025-05-20 07:47:23 瀏覽:225
怎麼修改華為wifi密碼 發布:2025-05-20 07:45:12 瀏覽:41
php函數遞歸 發布:2025-05-20 07:39:36 瀏覽:781
登陸認證失敗請檢查伺服器地址 發布:2025-05-20 07:06:55 瀏覽:831
無限分類實現php 發布:2025-05-20 06:57:40 瀏覽:681
數據結構c語言版嚴蔚敏李冬梅 發布:2025-05-20 06:55:05 瀏覽:449
iphone快捷訪問 發布:2025-05-20 06:55:05 瀏覽:929