android


how to do Json parse for send messge in android


public String sendMsg(String message) throws IOException, JSONException {
try {
sendmsgurl = "http://api.lociiapp.com/api/message/sendmessage?member_id="
+ 452
+ "&to_id="
+ 452
+ "&message="
+ "Travell Request"
+ "&Notificationtype="
+ "1"
+ "&notificationId="
+ "50011"
+ "&notify_status="
+ "false";
;
Log.e("Valueeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", sendmsgurl);
System.out.println("Valueeeeeeeeeeeeeeeeeee" + sendmsgurl);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonResp;
}
private String getResult(String response) {
String test = "";
try {
test=JSONfunctions.getJSONfromURL(sendmsgurl);
JSONObject _jobj = new JSONObject(test);
test = _jobj.getString("responseCode");
} catch (JSONException e) {
}
return test;
}
public class sendMesgTask extends AsyncTask<String, Void, Void> {
String msg = "";
#Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
try {
String result = sendMsg(params[0]);
msg = getResult(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
if (msg.equals("1")) {
} else {
}
}
}
and calling method like this in On create :
new sendMesgTask().execute(Sendername
+ ": Request For Travlling to You");
below is Json funcation Code:
public static String getJSONfromURL(String url){
InputStream is = null;
String result = "";
JSONObject jArray = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(url);
httppost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml,application/json;q=0.9,/;q=0.8");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8);
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
try{
jArray = new JSONObject(result);
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
return result;
}
When try to run this code then i am getting Exception and not getting repose code
and exception i am getting below is the Error:
Log-cat :
> 09-11 11:32:48.805: E/Valueeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee(15432):
http://api.lociiapp.com/api/message/sendmessage?member_id=453&to_id=454&message=Travell
Request&Notificationtype=1&notificationId=50011&notify_status=false
09-11 11:32:48.805: I/System.out(15432): Valueeeeeeeeeeeeeeeeeeehttp://api.lociiapp.com/api/message/sendmessage?member_id=453&to_id=454&message=Travell
Request&Notificationtype=1&notificationId=50011&notify_status=false
09-11 11:32:48.805: E/log_tag(15432): Error in http connection java.lang.IllegalArgumentException: Illegal character in query at
index 87:
http://api.lociiapp.com/api/message/sendmessage?member_id=453&to_id=454&message=Travell
Request&Notificationtype=1&notificationId=50011&notify_status=false
09-11 11:32:48.805: E/log_tag(15432): Error converting result java.lang.NullPointerException
09-11 11:32:48.805: E/log_tag(15432): Error parsing data org.json.JSONException: End of input at character 0 of
There is a space character in your url parameters. The space in 'Travel Request". Use URLEncoder.encode() before.

Related Links

IBM Worklight 5.0.x: Uncaught TypeError: Cannot call method 'init' of undefined
Run thread after app closes with Timer
How to transfer Arraylist from one fragment to another
Eclipse ADT: my project doesn't work anymore (verifyError). What can I do?
Android - App locale changes and displayed orientation
Android RelativeLayout Background Color
How to decode string to UTF-8 correctly? [closed]
Widget is not appearing in widget laucher section
Set a Margin between two buttons programmatically from a linearlayout
Android: Custom CursorAdapter to alternate resources
Qt Creator: No valid kits for Android found
How to annotation order field when using XStream on Android?
Layout Resize when keyboard appear (ScrollView)
Android Webview memory increases
Out of Memory Exception - Google Map GroundOverLay
How to calculate area of Irregular polygon drawn on map fragment using Google map API V2 in android? [duplicate]

Categories

HOME
search
localization
api
delphi-7
deep-learning
datastore
interface
hessian
devise
sublimetext
permissions
parameters
bookmarks
jetty
mapbox
jquery-ui
vert.x
pkcs#11
qpython
code-generation
atlassian
docx
symbol
altera
screen-readers
gruntfile
microsoft-dynamics-nav
null-pointer
boost-icl
jquery-callback
froala
jasmine-node
outliers
finagle
scrollview
panoramas
complex-numbers
fstream
github3.py
python-pptx
apic
sql-server-ce
ideascript
sessionstorage
android-augmented-reality
skylink
dapper-simplecrud
opencmis
optimizely
jide
textsum
opennms
openrasta
page-replacement
qtranslate
appdomain
oracleclient
android-testing
headless
monkey
flac
cpu-cache
py2neo
cd-burning
usart
grails-plugin
redistributable
greatest-n-per-group
x-tag
i386
hclust
fink
mobiledoc-kit
user-management
rasterize
libvlc
directdraw
google-books
evolus-pencil
zscript
canvg
snackbar
zxspectrum
public-html
iiop
filesplitting
ghcjs
dot42
android-audiorecord
embedded-fonts
ice-cube
chart-director
argouml
resource-management
zope.interface
node-redis
promotion-code
fsevents
automationelement
cuteeditor
diagrams
squishit
undefined-index
filesystemobject
silverlight-oob
tui
sun
business-model
dsoframer
wcf-proxy
mathematical-typesetting

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App