I have created and Android app that has to communicate with my website using JSON. JSON (on client, Android side) looks like this:
private static String JSONSend(Context ctx, JSONObject obj, String ObjName, String address) {
IHttpDispatcher disp = new HttpDispatcher();
Vector<String> ss = new Vector<String>();
String link = address;
String locale = uzmiLocale(ctx);
if(locale=="")
return "";
try {
obj.put("Lokal", locale);
ss.add(ObjName + obj.toString());
String ID = disp.getHttpResponse_POST(link, ss);
return ID;
} catch (Exception e) {
return "";
}
}
Above method is called from here:
public static String sendReq(Context ctx, String txt, String number) {
JSONObject jsn = new JSONObject();
try {
jsn.put("TextPoruke", txt);
jsn.put("BrTel", number);
return JSONSend(ctx, jsn, "JSNSend=", "www.mysite.com");
} catch (JSONException e1) {
return "";
}
}
Everything works fine on my Wamp server, but after moving my php code to webserver, nightmare started! Apparently, everything is sent the way it should be,but on serverside this php code is creating problems:
if(isset ($_POST['JSNSend']))
{
$argument = $_POST['JSNSend'];
$json = json_decode($argument,true);
$broj = $json['BrTel'];
$jsnLocale = $json['Lokal'];
it seems that result of "json_decode" is NULL, but $argument equals
{"\TextPoruke\": \"sometext\", \"BrTel\":\"111\"}
So passed JSON string seems ok, but for some reason it can't be decoded on webserver. Can anyone help me with this? Why it's not working?