你必須在服務器端編寫一個web服務。可以將數據作爲Json數據包發送到設備,並在設備中解析json數據包並訪問數據。你對Web服務調用應該是一個HTTP調用如
的http:\服務器\方法An Iteraitve \ get_somedata名=東西
和服務器應該在數據庫中查詢此參數併發送給您的效應初探爲JSON。 解析json並獲取您的詳細信息。
編輯: 在服務器響應頭中設置內容類型爲「application/json」。這是客戶端向服務器發送http post請求的一個例子。這裏jsonobjSend是json我已經構建發送到服務器的一些細節。 ex {table:「sometable」,id:90}。 jsonobjRecv是將服務器
HttpPost httpPostRequest = new HttpPost(url);
StringEntity se;
se = new StringEntity(jsonObjSend.toString());
// Set HTTP parameters
httpPostRequest.setEntity(se);
httpPostRequest.setHeader("Authorization", usercredential);
httpPostRequest.setHeader("Accept", "application/json");
httpPostRequest.setHeader("Content-type", "application/json");
httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression
long t = System.currentTimeMillis();
response = (HttpResponse) httpclient.execute(httpPostRequest);
Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
//Get hold of the response entity (-> the data):
HttpEntity entity = response.getEntity();
if (entity != null) {
// Read the content stream
InputStream instream = entity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
// convert content stream to a String
String resultString= convertStreamToString(instream);
Log.v(null, "resultString "+resultString);
instream.close();
// Transform the String into a JSONObject
if(resultString!=null){
jsonObjRecv = new JSONObject(resultString);
}
// Raw DEBUG output of our received JSON object:
Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");
return jsonObjRecv;
}
創建/分析JSON檢查json.org所
如何確保我在C#中的web服務實際上以JSON格式發送數據? – Dazzmaster1 2011-12-28 07:17:54