How can i convert the string with special characters into json object
Hi i am trying to parse the string and convert it in to JSONObject
.But it is not converted and giving the error like
"07-28 11:36:47.674: WARN/System.err(6050): org.json.JSONException: Unterminated string at character 313开发者_JS百科6 of {"data":[{""...."(there is my data)
First i thought there is some special characters like ~,@,%,&
and replace the characters with " "
but there is no result and giving the same error.
And i modified the web services data by encoding with UTF-8
format. and i used the code to get decode the UTF-8
formatted data in my application.here is my code:
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
params.setBooleanParameter("http.protocol.expect-continue",false);
HttpClient httpclient = new DefaultHttpClient(params);
HttpGet httpget =new htpGet("http://www.mylink.com"+todaydate);
try
{
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
jsonText = EntityUtils.toString(entity, HTTP.UTF_8);
Log.d("TEST", jsonText); /this is the result string
}
catch (Exception e)
{
}
JSONObject jObj = new JSONObject(jsonText.toString());
Here i cannot convert the string(jsonText
) into json object(jobj)
.But in logcat it is displaying the string jsonText
perfectly. Is there any suggestion to get the data as json object.
I need to use the Json object
in my application.
If you are certain that the JSON data is valid and no special characters are causing problems then "Unterminated string at character" could mean that you have not received the whole string.
You could prove this by checking a substring from the end and displaying that in logcat
If not then you need to start looking for the special characters again
精彩评论