Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Convert JSON to UFT-8
    primarykey
    data
    text
    <p>I need help converting JSON response to UTF-8. Everything worked perfectly when i had saved my .json file with UTF-8 (without BOM). When I saved the file with only UTF-8 it would not work, the app crashes while getting JSON now.</p> <p>Logcat at bottom</p> <p>The source:</p> <pre><code>.. public class JSONPARSER extends ListActivity { private static String url = "http://profusum.se/neger.json"; private static final String TAG_CONTACTS = "messages"; private static final String TAG_NAME = "namn"; private static final String TAG_ID = "id"; private static final String TAG_KIK = "facebook"; private static final String TAG_IMGURL = "img"; JSONArray contacts = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drivers); ArrayList&lt;HashMap&lt;String, String&gt;&gt; contactList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(url); try { contacts = json.getJSONArray(TAG_CONTACTS); for(int i = 0; i &lt; contacts.length(); i++){ JSONObject c = contacts.getJSONObject(i); // Storing each json item in variable String id = c.getString(TAG_ID); String name = c.getString(TAG_NAME); HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // adding each child node to HashMap key =&gt; value map.put(TAG_ID, id); map.put(TAG_NAME, name); contactList.add(map); } } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } ListAdapter adapter = new SimpleAdapter(this, contactList, R.layout.list_item, new String[] { TAG_NAME,}, new int[] { R.id.inboxName, }); setListAdapter(adapter); ListView lv = getListView(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { String name = ((TextView) view.findViewById(R.id.inboxName)).getText().toString(); Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(TAG_NAME, name); startActivity(in); } }); } } </code></pre> <p>I've searched hard for this now, my guess it's simple..but I can't figure it out.</p> <pre><code>05-01 21:13:08.213: E/JSON Parser(27153): Error parsing data org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject </code></pre> <p><strong>Summary</strong></p> <p>When i save the file with "UTF-8 (without BOM)" in Notepad++ the parsing is successful. But I get these weird symbols in the app.(see example)</p> <p>But when I save the file with "UTF-8" in Notepad++ the JSON gives me the correct symbols, but the Android app won't parse it.</p> <pre><code>Example Tim Billström </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload