title: why I get error message Value ï»¿<?xml of type java.lang.String cannot be converted to JSONObject?
body: <p>I've create a web service with JSON and I want to parse it then put them on listview. but when I run the application, it force close and shows error message. please review my code, is there something wrong?</p>
  
  <p>Here is the error message when i try to run my aplication:</p>
  
  <pre><code>org.json.JSONException: Value ï»¿&lt;?xml of type java.lang.String cannot be converted to JSONObject
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>public class WeeklyFlashActivity extends ListActivity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.listplaceholder);
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
          JSONObject json = JSONfunctions.getJSONfromURL("http://www.greenfields.co.id:502/Service1.svc/json/weeklyflash");
  
          try{
  
              JSONArray  weeklyflash = json.getJSONArray("GetReportResult");
  
              for(int i=0;i&lt;weeklyflash.length();i++){                        
                  HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();    
                  JSONObject e = weeklyflash.getJSONObject(i);
  
                  //map.put("type",  String.valueOf(i));
                  map.put("type", e.getString("type"));
                  map.put("total", e.getString("total"));
  
                  mylist.add(map);            
              }       
          }catch(JSONException e)        {
               Log.e("log_tag", "Error parsing data "+e.toString());
          }
  
          ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, 
                          new String[] { "type", "total" }, 
                          new int[] { R.id.item_title, R.id.item_subtitle });
  
          setListAdapter(adapter);
  
          final ListView lv = getListView();
          lv.setTextFilterEnabled(true);  
          lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {              
                  @SuppressWarnings("unchecked")
                  HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) lv.getItemAtPosition(position);                   
                  Toast.makeText(WeeklyFlashActivity.this, "Type " + o.get("type") + " was clicked.", Toast.LENGTH_SHORT).show(); 
  
              }
          });
      }
  }
  </code></pre>
  
  <p>here is my JSON variable:</p>
  
  <pre><code>{"GetReportResult":[{"total":"249319","type":"ESL500ML"},{"total":"19802","type":"CHEESE1K"},{"total":"3179380","type":"ESL"},{"total":"201243","type":"WHP"},{"total":"736744.136","type":"UHT"}]}
  </code></pre>
  
  <p>here is my JSONfunction:</p>
  
  <pre><code>public class JSONfunctions {
      public static JSONObject getJSONfromURL(String url){
  
          //initialize
          InputStream is = null;
          String result = "";
          JSONObject jArray = null;
  
          //http post
          try{
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost(url);
              HttpResponse response = httpclient.execute(httppost);
              HttpEntity entity = response.getEntity();
              is = entity.getContent();
  
          }catch(Exception e){
              Log.e("log_tag", "Error in http connection "+e.toString());
          }
  
          //convert response to string
          try{
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              result=sb.toString();
          }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
          }
  
          //try parse the string to a JSON object
          try{
                  jArray = new JSONObject(result);
          }catch(JSONException e){
              Log.e("log_tag", "Error parsing data "+e.toString());
          }
  
          return jArray;
      }
  
  }
  </code></pre>
  
  <p>UPDATE: I've check my result and the result is a html code and says <code>Method not allowed.</code> maybe the problem comes from my wcf service. do you have any solution for this?</p>
  
  <p>here is my wcf service:</p>
  
  <pre><code>[WebInvoke(Method = "GET",
              ResponseFormat = WebMessageFormat.Json,
              BodyStyle = WebMessageBodyStyle.Wrapped,
              UriTemplate = "/json/weeklyflash")]
  </code></pre>