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

Sending opt in links using email to start Apps not working
how to delete row with where clause?
Published app with a typo in the package name
OnErrorNotImplementedException Caused by: rx.exceptions.MissingBackpressureException
how can i create directory using DocumentsContract.CreateDocument on android kitkat?
Android GridView scrolling with ImageButtons
ShadowIntent is null - Robolectric 3.0
allow access to devices not asked, in one plus 2 phone, when downloading app from google store
Android - Listening to a locale change without static variables
Printing strings on screen
Back Button (activity) Return To Fragment
How to change icon and gravity of Navigation Drawer?
Capture image on current drawing state
ANDROID_HOME not set (VSTS agent running as service on OS X)
How can I override uses-feature and uses-permission
Get a TextView in an AsyncTask - Android

Categories

HOME
asp.net-web-api
api
cobalt
hyperlink
ggplot2
twig
yahoo-finance
graphics
error-handling
tail
iis-6
pcl-crypto
radgridview
dynatrace
entitymanager
dreamweaver
forgot-password
spring-async
draft-js-plugins
siri
shared
asymptotic-complexity
amazon-quicksight
gp
xbox
zend-debugger
paragraph
card.io
login-script
gojs
classcastexception
latitude-longitude
apic
openproject
graphhopper
protein-database
mongoose-schema
mcustomscrollbar
subclipse
apollostack
importerror
strftime
mesosphere
robomongo
fclose
twilio-click-to-call
tf
context-switch
avx
sundials
bootstrap-tags-input
nikeplus-api
eigenvector
jclouds
nservicebus5
lz77
libav
state-restoration
opl
grgit
dllimport
intel-c++
poppler
visual-sourcesafe-2005
uncompress
avahi
fail2ban
rrule
dbaccess
theos
execve
ghcjs
ora-00904
tinyxml
radiant
terminate
decoupling
menubar
model-driven-development
hidapi
dolby-audio-api
superscrollorama
frameworkelementfactory
rmiregistry
adobe-media-server
paginator
predicatebuilder
cgimage
google-maps-mobile
entity-attribute-value
promotion-code
fsevents
tmx
load-time
silent
opml

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