Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:32:53+00:00 2026-06-14T01:32:53+00:00

I want to send a JSON like this: {reverseme : Reverse Me! } So

  • 0

I want to send a JSON like this:

{"reverseme" : "Reverse Me!" }

So I created this Java:

JSONObject jsonToSend = new JSONObject()
    .put("reverseme", "Reverse ME!")

If I transform it to String and send it to my api I have no problems:

HttpClient client = new HttpClient();
HttpPost post = new HttpPost("http://192.168.0.10/api");

List<NameValuePair> postData= new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("json", jsonToSend.toString()));

post.setEntity(new UrlEncodedFormEntity(postData));

There it will go to my PHP API is as simple as this (i’m testing some things):

<?php 
$JSON = json_decode($_POST['json'], true);

print(
    json_encode( Array(
        'reversed' : strrev($JSON['reverseme'])
    ))
); ?>

Finally, Java Code to read the response is this:

HttpResponse httpresponse = client.execute(post);
String jsonstringresponse = EntityUtils.toString(httpresponse.getEntity()); 
JSONObject jsonresponse = new JSONObject(jsonstringresponse);

It gives me this StackTrace:

org.json.JSONException: A JSONObject text must begin with '{' at character 1 of "{\"reversed\": "!EM esreveR"}"
    at org.json.JSONTokener.syntaxError(JSONTokener.java:448)
    at org.json.JSONObject.<init>(JSONObject.java:178)
    at org.json.JSONObject.<init>(JSONObject.java:246)
 -> at com.example.test.MainActivity.onClick(MainActivity.java:67)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at android.view.View$1.onClick(View.java:2026)
...

Of course I, as you can see on StackTrace’s last line I have some Android UI that read from a EditText and put JSONresult to a TextView.

The problem is that from server it comes:

"{\"reversed\": "!EM esreveR"}"

What is the problem here? Why does json_encode escape every character? Is it Charset problem or some need of cleaning or what?

Thanks on any advise.


UPDATE 1
On Apache error log I found this line:

[error] PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in /var/www/controllers/api.inc.php on line 4.

I have thought that it could be even a PHP misconfiguration?


UPDATE 2

json_encode was receiving a Spanish String, that’s the reason of that error: Reading “Atención” gives error because of ‘ó’.

I’m temporally using stripslashes() and deleting first and last character to make it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:32:54+00:00Added an answer on June 14, 2026 at 1:32 am

    Was a Server configuration fault and that the PHP was saved on ISO-8859-1 charset so PHP messed with 3 different charsets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to send JSON with POST/PUT i don't know if it's the same
My question: How can I parse a json array? I send it like this:
i want to send a json string from a html webpage using javascript to
I have a webservice and I want to send a JSON string to it
I made a JSON string with jquery, and i want to send it to
I want to send a JSON object from the client to an action on
I want to send a few variables and a string with the POST method
I have a JSON encoded array that looks like this (it came from a
I'm running XMLHttpRequest request like this: var data = JSON.stringify({ name : 123, id
I tried to send an array as part of an ajax request like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.