Please how i can retrieve data and username from web socket,
io.sockets.emit('update chat', 'username':socket.username, 'data':data);
i'm sending data from android to socket then i want retrieve this data in my server chat but i get [object object],
You may need to use JSON.stringify before emiting the data variable like
io.sockets.emit('update chat'
, 'username':socket.username
, 'data':JSON.stringify(data));
and parse same string back to json form at recieving end via JSON.parse like
var objData = JSON.parse(data);
Related
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!
I am developing an android application and i need to parse the json data from YQL
https://query.yahooapis.com/v1/public/yql?q=select%20%20*%20from%20%20yahoo.finance.historicaldata%20where%20symbol%20in%20(%27YHOO%27)%20and%20startDate%20%3D%20%272016-01-01%27%20and%20endDate%20%3D%20%272016-04-10%27&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
I am using JsonReader to access the Count and the Result object. The problem am facing is how do I check the object name and then call beginobject on results object . I am able to fetch the counts value though from the Json Feed
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.
I have two links :
private static final String url_to_reg_device1 = "http://10.0.2.2/android_connec/regdevice.php";
private static final String url_to_reg_device2 = "http://www.something.in/form/regdevice.php";
One is for localhost and another is for server.
When I start activity, I create one JSON which store email and reg number and send it to server. On the server side, I decode JSON record and get values, store it in db.
The problem is that my code is working on local server. But when I upload it on server (to the URL in url_to_reg_device2), I got this error:
"Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject".
Check tags of JSON Object properly.
i have JSON FILE on my localhost i
want to update it via code how i do that any help plz ?
i have list.JSON ON MY LOCAL
HOST i want delete all data in it and
write new data in it
and update it on server ?
can any one tell me how i do that ?
///////////////////////////////////////////////
//////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////
///////////////////////////////////////
//////////////////////////////////
///////////////////////////
////////////////////
How to send a JSON object over Request with Android?
1- crate a page on server which takes this json and update it and take it's url
2- take the input from user
3- put it in a bean/model (wrap in object form as per structure )
4- crate the json from object (can use libraries like GSON for this
5- use post method to push json to srver