Posting JSON from Android to php page - android

Need to post JSON data to the server , i have valid json object.
My problem is that, {"code":"400","message":"Failed loading JSON. Special characters must not be included in the request. Please check the requested JSON."}
This is my URL :- http://www.invoicera.com/app/api/check_json_api.php?token=7B92C122473A3D6F54E60D20AC5526D0
And this is my JSON Data which i want to post :- { "listInvoice" : {
"client_id":"",
"date_from":"",
"date_to":"",
"invoice_number":"",
"invoice_record_status":"Draft",
"invoice_status":"Active",
"page":"1",
"per_page_record":"10"
}
}

Related

How do I construct and pass raw json data with okHttpClient in android

I am using a query where I need to POST to an endpoint with okhttpclient.
The issue is I have the payload value and the senttime. I just don't know how to create a json object to send over as a raw body object to the endpoint.
To make things more clear:
here's my postman screenshot:
enter image description here
This is my post request :
https://example.org/api/service-profile/v1/device-notification/{deviceId}
Now I am planning to pass {deviceId} in the path, authorization token in the header and finally , as raw payload query like this in the body :
{
"payload": {"notificationID":"677291f5-a784-43df-af2e-0363a4067e9c","title":"test 223","body":"payload","lockScreenVisibility":1,"groupMessage":"","fromProjectNumber":"819539062812","priority":5,"rawPayload":"{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1591849563191,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"i\\\":\\\"677291f5-a784-43df-af2e-0363a4067e9c\\\"}\",\"oth_chnl\":\"\",\"pri\":\"5\",\"abc\":\"1\",\"from\":\"819539062812\",\"alert\":\"payload\",\"title\":\"test 223\",\"grp_msg\":\"\",\"google.message_id\":\"0:1591849563205759%409ebbcaf9fd7ecd\",\"google.c.sender.id\":\"819539062812\",\"notificationId\":-1451117355}"}
,
"sentTime": 1591849563191
}
trouble is I have the payload value and senttime, but I dont know how to construct a json object such that i can create the structure as { "payload" :pass in my payload value, "senttime":pass in sent time}
and then pass it as a raw body param over okhttpclient? Any idea how to accomplish this?
Thanks!

Retrieve ID of JSON when POST in Firebase, Android

I POST a JSON into my Firebase Database, using okHttp. Then I retrieve a response and I do:
response.body().string();
But when I print this, instead of a JSON I get:
/**/ gotData({"name":"my_object_ID"});
I want to extract the JSON inside of that String.

How to read this below type of response in Android using retrofit ?

I have a post link which response back below type of json.
{
"response": "100100000001"
}
I want to store that response code in a variable.

Ajax post data in android java

I am new t ajax, but quite familiar with android. I am converting a ajax program to android app. As a part of it, i need to post data to the server. Below is the given post command in ajax.
var postTo = 'xyz.php';
$.post(postTo,{employee_name: $('[name=employee_name]').val() , phone: $('[name=phone]').val(), employee_type: 'guest' } ,
function(data) {
if(data.success){
window.localStorage["sa_id"] = data.mid;
window.location="getempdb.html";
}
if(data.message) {
$('#output').html(data.message);
} else {
$('#output').html('Could not connect');
}
},'json');
I want to implement this in android but under very little from the above statements. Could anyone who is good at ajax help me out with this thing. As of now, i get the user name and telephone number as a edit text input. I need to send this to php using http client. I know how to send data using php, but do not know what format to send and whether its a string to send or as a json object to send. Please help in interpreting the above code and oblige.
Apparently, this uses UrlEncodedFormEntity if you are using HttpClient in android.
This is created by using a List of NameValuePair.
from the parameters to the $.post:
{employee_name: $('[name=employee_name]').val() , phone: $('[name=phone]').val(), employee_type: 'guest' }
You have to create a NameValuePair for employee_name, one for phone ... each of which is fetched from a HTML element name employee_name, phone ... This is where you put the values from your EditTexts.
It returns a JSON formatted String, which you have to parse (typically using JSONObject obj = new JSONObject(result); once you have fetched the result from the server)
In this JSON object, you have a key named success, which format is not specified, except you can assume things went well if it is present ; a key mid, and a key message.

How to remove the special characters when getting the data using json in android?

I am working on android application. I need to get the data from PHP web service. The response which I am getting from PHP server is shown below:
String response = [{id:100,category:local,count1:58,count2:86},
{id:101,category:server/local,count1:18,count2:27},
{id:102,category:server & local,count1:19,count2:28}];
But I am getting the following message when I am trying to separate the data using JSON.
org.json.JSONException: Unterminated object at character
How to remove special characters and get the data using JSON array?
Strings should be under double quotes. Your json is not a valid response. So change your response from
{id:100,category:local,count1:58,count2:86}
to
{
"id":100,
"category":"local",
"count1":58,
"count2":86
}
Refer here
Valid JSON format
{
"Status":"OK",
"Error":{
"Code":0,
"Description":""
},
"Data":[]
}

Categories

Resources