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
Related
I have a URL which return a file.gz , i need to get the json data from this URL .. how can i do that?
I need the answer of the two steps i should follow
1- get the file from url
2- get the json data from this file
We are getting the request from Android app as json array. For example:
$var = [{"username":"kp","mailid":"kp#gmail.com","phoneno":"9876543563","groupname":"android"}]';
I want to make this static data (kp, kp#gmail.com, 9876543563, android) as dynamic to insert the values into database.
In what method we are getting the data? And from an android app, is it POST or GET variable, or an other method? Please let me know how to make this value dynamic which is coming from the android app.
How to do you want to send the data from Android App? Is it needed to be namely JSON-format?
I think the most useful case is to use usual, e.g., POST data and retrieve this using base methods to save it inside PHP. You can use, of course, GET format for 'short' request.
For instance,
Android sends using GET: http://yourcompany.com/senddata?username=name&mailid=e#yourmail.com
You PHP code (very-very-very simple approach):
/// ... initialization...
$sql = "INSERT INTO users (username, email) VALUES ('". ($_POST["username"]) . "', '". ($_POST["mailid"]) . "')";
mysqli_query($conn, $sql)
PHP insert example
To create POST or GET request in Android I would recommend to use JSOUP library
Download
A simple example for jsoup:
Document doc = Jsoup.connect("http://yourcompany.com/url?var1=a").get();
I am getting data from server by building a get request (HttpRequest). The data is not in Json format (when I open the link in a web browser, it says "This XML file does not appear to have any style information associated with it. The document tree is shown below.")
Since it is the case, when I call this line:
HttpRequest request = buildGetRequest("TreeLocation");
final LocationListResponse response = request.execute().parseAs(getResultType());
The app stops there, and I think it is because it does not regconize the resultType.
So, now I want to declare the content type as Json. Anyone knows how to declare the content type in Google http client library?
just convert your xml response into json using json library..and then you will get json response
use this link Convert XML to JSON object in Android
Edit 1:
you can add this and try
httpPost.setHeader("Content-type", "application/json");
for json respomse
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);
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.