आपको सर्वर की तरफ एक webservice लिखना है। डिवाइस को जेसन पैकेट के रूप में डेटा भेज सकते हैं और डिवाइस में जेसन पैकेट को पार्स कर सकते हैं और डेटा तक पहुंच सकते हैं। ? वेब सेवा करने के लिए अपने कॉल एक http कॉल जैसे
http होना चाहिए: \ सर्वर \ metnod \ get_somedata नाम = कुछ
और सर्वर इस पैरामीटर के लिए डेटाबेस क्वेरी और JSON के रूप में आप प्रतिक्रिया भेजना चाहिए। पार्स जेसन और अपना विवरण प्राप्त करें।
संपादित करें: सर्वर प्रतिक्रिया शीर्षलेख में सामग्री-प्रकार "एप्लिकेशन/जेसन" के रूप में सेट करें। क्लाइंट के लिए सर्वर पर http पोस्ट अनुरोध भेजने के लिए यह एक उदाहरण है। यहां jsonobjSend जेसन है जिसे मैंने कुछ विवरणों के साथ सर्वर को भेजने के लिए तैयार किया है। पूर्व {तालिका: "कुछ समय", आईडी: 9 0}। jsonobjRecv json जो सर्वर
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 जांच
मैं कैसे सुनिश्चित करूं कि सी # में मेरी webservice वास्तव में JSON प्रारूप में डेटा भेजती है? – Dazzmaster1
मैंने जवाब संपादित किया है। कृपया मुझे बताएं कि यह आपके लिए पर्याप्त है – AD14
तो क्या ग्राहक निर्धारित करता है कि यह डेटा किस प्रारूप को प्राप्त करता है? मुझे सर्वर की तरफ कुछ भी अलग करने की ज़रूरत नहीं है? – Dazzmaster1