Q:

Parsing JSON gives error org.json. JSONException: Expected literal value

Hi i have a JSON file saved in a txt file and i am parsing it in my android code.  I keep getting a JSONSyntax lateral exception.  I used a json validator and my json syntax is correct.  I really don't know the problem.  Can someone pls help me out. 
I used this JSON object array in my file
    {"destinations": [
        {
            "name": "Aegean Coast",
            "id": "001"
        },
        {
            "name": "Black Sea",
            "id": "002"
        },
        {
            "name": "Central and eastern Anatolia",
            "id": "003"
        },
        {
            "name": "Istanbul",
            "id": "004"
        },
        {
            "name": "Lycian Way",
            "id": "005"
        },
        {
            "name": "Georgia",
            "id": "006"
        }
    ]
}

This is my android class fragment where i access my json objects:
        public class DestinationsFragment extends Fragment {
    private GoogleMap map;

     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            View rootView = inflater.inflate(R.layout.fragment_destinations, container, false);
            ListView listview= (ListView)rootView.findViewById(R.id.list);
            String feed = loadJSONFromAsset();

            try {
                 ArrayList<String> items = new ArrayList<String>();
              JSONArray jsonArray = new JSONArray(feed);
              for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
             String name= jsonObject.getString("name");
             items.add(name);
             Log.d(name,"Output");
              }
              ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),R.layout.list_item, items);
              listview.setAdapter(adapter);

            } catch (Exception e) {
              e.printStackTrace();
            }

            return rootView;
        }

     public String loadJSONFromAsset() {
            String json = null;
            try {

                InputStream is = getActivity().getAssets().open("destinations.txt");
                int size = is.available();
                byte[] buffer = new byte[size];
                is.read(buffer);
                is.close();
                json = new String(buffer, "UTF-8");

            } catch (IOException ex) {
                ex.printStackTrace();
                return null;
            }
            return json;

}
}

This is my logcat error ouput:
 06-02 11:51:47.027: W/System.err(6304): org.json. JSONException: Expected literal value at character 1 of {\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf200
06-02 11:51:47.027: W/System.err(6304): {\fonttbl\f0\fmodern\fcharset0 CourierNewPSMT;}
06-02 11:51:47.027: W/System.err(6304): {\colortbl;\red255\green255\blue255;}
06-02 11:51:47.027: W/System.err(6304): \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
06-02 11:51:47.027: W/System.err(6304): \deftab720
06-02 11:51:47.027: W/System.err(6304): \pard\pardeftab720
06-02 11:51:47.027: W/System.err(6304): \f0\fs28 \cf0 \{"destinations": [\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Aegean Coast",\
06-02 11:51:47.027: W/System.err(6304):             "id": "001"\
06-02 11:51:47.027: W/System.err(6304):         \},\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Black Sea",\
06-02 11:51:47.027: W/System.err(6304):             "id": "002"\
06-02 11:51:47.027: W/System.err(6304):         \},\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Central and eastern Anatolia",\
06-02 11:51:47.027: W/System.err(6304):             "id": "003"\
06-02 11:51:47.027: W/System.err(6304):         \},\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Istanbul",\
06-02 11:51:47.027: W/System.err(6304):             "id": "004"\
06-02 11:51:47.027: W/System.err(6304):         \},\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Lycian Way",\
06-02 11:51:47.027: W/System.err(6304):             "id": "005"\
06-02 11:51:47.027: W/System.err(6304):         \},\
06-02 11:51:47.027: W/System.err(6304):         \{\
06-02 11:51:47.027: W/System.err(6304):             "name": "Georgia",\
06-02 11:51:47.027: W/System.err(6304):             "id": "006"\
06-02 11:51:47.027: W/System.err(6304):         \}\
06-02 11:51:47.027: W/System.err(6304):     ]\
06-02 11:51:47.027: W/System.err(6304): \}}
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONTokener.syntaxError(JSONTokener.java:450)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONTokener.readLiteral(JSONTokener.java:285)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONTokener.nextValue(JSONTokener.java:111)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONTokener.readObject(JSONTokener.java:362)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONTokener.nextValue(JSONTokener.java:100)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONArray.<init>(JSONArray.java:87)
06-02 11:51:47.037: W/System.err(6304):     at org.json. JSONArray.<init>(JSONArray.java:103)

'

A:

Your json looks valid.  
 { // Json object node 
 "destinations": [ // json array destinations 
  {          // json object node 
    "name": "Aegean Coast", 
    "id": "001"
  },

Your json is not a JSONArray its a JSONObject.  Your parsing seems wrong
Change this
 JSONArray jsonArray = new JSONArray(feed);

to
JSONObject jsonObject = new JSONObject(feed); 

Then
JSONArray jsonArray = jsonObject.getJSONArray("destinations");
 for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        String name= jsonObject.getString("name");
        items.add(name);
        Log.d(name,"Output");
 }

