JSONObject text must begin with '{' at character 1 of
<p>I had a PHP API which showed a JSON Array, which I then read into an Android Application.</p>

<p>I since moved servers and the android application broke.</p>

<p>I assumed it was the Authentication and thought I would re-build the Android application (Was my first application and thought a re-write could make things better)</p>

<p>For some reason I am now getting this exception error</p>

<p>I read somewhere that I need to parse JSON_FORCE_OBJECT in the PHP json_encode </p>

<pre><code>json_encode($arrMyData, JSON_FORCE_OBJECT);
</code></pre>

<p>But I am running PHP 5.2 (Options parameter came out in PHP 5.3)</p>

<p>My code for you to rip into</p>

<pre><code>private void displayAllStories(){

    String line;
    int intNumStories       = 0;
    JSONObject arrAllStories;
    LinearLayout storiesLayout = (LinearLayout) findViewById(R.id.lyoutStoriesMain);
    storiesLayout.removeAllViewsInLayout();
    try {

        while((line = this.jsonResult.readLine()) != null){
            JSONObject arrStories;
            arrStories              = new JSONObject(line.trim());
            intNumStories           = Integer.parseInt(arrStories.optString("NumStories"));
            arrAllStories           = arrStories.getJSONObject("StoryData");

            this.strDebug += "We have "+intNumStories+"\n";
        }
    } catch (IOException e) {
        this.strDebug += "Error (3) "+e.getLocalizedMessage()+"\n";
    } catch (JSONException e) {

        this.strDebug += "Error (4) "+e.getLocalizedMessage()+"\n";
    }
}
</code></pre>

<p>And the encoded data from the website</p>

<pre><code>{
   "NumStories":1,
   "StoryData":{
      "Story0":{
         "ID":"1020",
         "OWERNAME":"Alicia",
         "STORYMAIN":"Good evening my son was born with bilateral club feet. When he was a week old we started serial casting once a week for 3 months and then he was placed in braces for the next 6 months for a 23 hour period and then for the next 3 months just durning the night. This last visit the doctor said that he needs to have his tendons lengthened and he will go back into cast. After reading all of these articles I am a little scared on what will be best for him. It sounds like the risk of having the surgery are just as heavily weighed as just keeping him in AFO\\'s till he can make his own decision. I would like all advice whether it be positive or negative. Thank you in advance for your help.",
         "STORYBRIEF":"Need reassurance that tendon lengthening is the best decision.",
         "ADDEDDATE":"2011-12-12 00:51:16",
         "CURRENTSTATUS":"n"
      }
   }
}
</code></pre>

<p>Sorry I should add, the code before this which procudes jsonResult is as follows</p>

<pre><code> try{
            URL url                     = null;
            URLConnection urlConn       = null;
            InputStreamReader jsonIsr   = null;
            BufferedReader jsonBr       = null;

            //this.strDebug += "URL is "+this.strURL+"\n";
            url = new URL(this.strURL);

            urlConn = url.openConnection();

            jsonIsr = new InputStreamReader(urlConn.getInputStream());

            jsonBr = new BufferedReader(jsonIsr, 8192);

            this.jsonResult = jsonBr;

            return true;


        }catch(MalformedURLException e){
            this.strDebug += "JSON Error (1) "+e.getLocalizedMessage()+"\n";
        }catch(IOException e){
            this.strDebug += "JSON Error (2) "+e.getLocalizedMessage()+"\n";
        }
    }else{
        strDebug = "NO URL Passed to JSON\n";
    }
</code></pre>

<p>// EDIT 2</p>

<p>For those who asking</p>

<p>The error is as the title says</p>

<pre><code> Error (4) A JSONObject text must being with '{' at character 1 of {"NumStories":1, "StoryData":........
</code></pre>
