title: Can't resolve JSONException Android Studio
body: <p>I don't know what's going wrong with my <strong>JSONData</strong>, but my code catch <strong>JSONException</strong>, maybe it's invalid value ...? My url with json data is : <a href="http://www.bundoransurfco.com/events/?json=1" rel="nofollow">this website</a> . I already used <strong>Json</strong> with this website, and it works, but not this page with Json... Why ?</p>
  
  <p>Here is my code :</p>
  
  <pre><code>public class Tab4Fragment extends Fragment {
  
      private ConnectivityManager manager;
      public static final String TAG = Tab4Fragment.class.getSimpleName();
      private CurrentEventsString mCurrentEventsString;
      @InjectView(R.id.eventsText)
      TextView mJsonText;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (container == null) {
              return null;
          }
  
          View view = inflater.inflate(R.layout.tab_frag4_layout, container, false);
          ButterKnife.inject(this, view);
  
          String urlWebSite = "http://www.bundoransurfco.com/events/?json=1";
  
          if (isNetworkAvailable()) {
              OkHttpClient client = new OkHttpClient();
              Request request = new Request.Builder()
                      .url(urlWebSite)
                      .build();
  
              Call call = client.newCall(request);
              call.enqueue(new Callback() {
                  @Override
                  public void onFailure(Request request, IOException e) {
                      Log.d(TAG, "onFailure Network");
                  }
  
                  @Override
                  public void onResponse(Response response) throws IOException {
                      try {
                          String jsonData = response.body().string();
                          Log.d(TAG, "onResponse jsonData : "+jsonData);
  
                          if (response.isSuccessful()) {
                              mCurrentEventsString = getCurrentDetails(jsonData);
                              Log.d(TAG, "onResponse Successful");
  
                              // Write in the main Thread.
                              getActivity().runOnUiThread(new Runnable() {
                                  @Override
                                  public void run() {
                                      updateTextEvents();
                                      Log.d(TAG, "UITHREAD");
                                  }
                              });
  
                          } else {
                              alertUserAboutError();
                              Log.d(TAG, "ERROR");
                          }
                      } catch (IOException e) {
                          Log.e(TAG, "Exception caught: ", e);
                      } catch (JSONException e) {
                          Log.e(TAG, "Exception caught: ", e);
                      }
                  }
              });
          } else {
              Toast.makeText(getActivity(), getString(R.string.network_unavailable_message), Toast.LENGTH_LONG).show();
          }
  
          Log.d(TAG, "Main UI code is running!");
  
          return view;
      }
  
      private void updateTextEvents() {
          mJsonText.setText(mCurrentEventsString.getJsonContent());
      }
  
  
      private boolean isNetworkAvailable() {
          manager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo networkInfo = manager.getActiveNetworkInfo();
          boolean isAvailable = false;
          if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
          isAvailable = true;
          }
  
          return isAvailable;
          }
  
      private void alertUserAboutError() {
          AlertDialogFragment dialog = new AlertDialogFragment();
          dialog.show(getActivity().getFragmentManager(), "error_dialog");
      }
  
      private CurrentEventsString getCurrentDetails(String jsonData) throws JSONException {
          JSONObject events = new JSONObject(jsonData);
  
          JSONObject postJson = events.getJSONObject("posts");
          CurrentEventsString currentEventsString = new CurrentEventsString();
          String contentString = postJson.getString("content");
  
          //Events String
          String jsonText = stripHtml(contentString);
          Log.i(TAG, "CHECK THAT :" +jsonText);
          currentEventsString.setJsonContent(jsonText);
  
  
          return currentEventsString;
      }
  
      //Delete HTML Markup
      public String stripHtml(String html) {
          return Html.fromHtml(html).toString();
      } 
  }
  </code></pre>
  
  <p>My code stop after <code>String jsonData = response.body().string();</code> and go in <code>Log.e(TAG, "Exception caught: ", e);</code></p>
  
  <p>I would like to have the string from <strong>Posts</strong> > <strong>content</strong></p>
  
  <p>How can I solve this ? Cheers!</p>
  
  <p>Logcat :</p>
  
  <pre><code>04-24 05:58:46.696    2140-2140/jardelcompany.bundoransurfco D/Tab4Fragment﹕ Main UI code is running!
  04-24 05:58:47.228    2140-2174/jardelcompany.bundoransurfco D/Tab4Fragment﹕ onResponse jsonData : {"status":"ok","count":1,"pages":1,"category":{"id":6,"slug":"events","title":"Events","description":"","parent":0,"post_count":1},"posts":[{"id":6969,"type":"post","slug":"2014-calander-of-events","url":"http:\/\/www.bundoransurfco.com\/events\/2014-calander-of-events\/","status":"publish","title":"2015 Calendar of Events","title_plain":"2015 Calendar of Events","content":"&lt;p&gt;We open all year and have all our regular&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/beginners\/\"&gt; surf lessons &lt;\/a&gt;and also &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-stay\/lodge-packages\/\"&gt;surf and stay packages available year round&lt;\/a&gt;.&lt;\/p&gt;\n&lt;p&gt;We also have &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-camp\/\"&gt;week long surf camps&lt;\/a&gt; as well as &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/family-surf-and-stay-packages\/\"&gt;family surf and stay packages &lt;\/a&gt;all year.\u00a0Below is a\u00a0list of specific\u00a0events. We are open for other bookings when the events below are on. We can be flexible with dates for group bookings\u00a0and arrange specific packages : just call on 071-9841968 or email info@bundoransurfco.com.&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;February 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;7th-8th &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/improver-surf-weekends\/\"&gt;Improvers Surf Weekend with Surf Fit Ireland&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;13th-15th&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-guiding\/\"&gt;\u00a0Surf Guiding weekend.&lt;\/a&gt; Explore the coast with our instructors. For improver and intermediate surfers&lt;\/p&gt;\n&lt;p&gt;20th-22nd\u00a0&lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/singles-weekend\/\"&gt;Single Surfers Valentines Surf Weekend&lt;\/a&gt;. Meet new people, catch a few waves, have the craic. Only \u20ac79pps&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;March 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;7th-8th\u00a0&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/improver-surf-weekends\/\"&gt;Improvers Surf Weekend with Surf Fit Ireland&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;13th-15th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt;Get Ready for Summer Surf Weekend&lt;\/a&gt;. For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;20th-22nd\u00a0&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-guiding\/\"&gt;Surf Guiding weekend.&lt;\/a&gt; Explore the coast with our instructors. For improver and intermediate surfers&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga weekend&lt;\/a&gt;.&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;April 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;3rd-6th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/easter-surf-packages\/\"&gt;Easter Surf Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;17th-19th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt;Get Ready for Summer Surf Weekend&lt;\/a&gt;. For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;24th-26th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;May 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;1st-4th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/may-bank-holiday-surf-weekend-2\/\"&gt;May Bank Holiday Surf Weekend&lt;\/a&gt;.\u00a0Surf, B&amp;B, craic and BBQ&lt;\/p&gt;\n&lt;p&gt;8th-1oth &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/sup-tours\/\"&gt;Surf and SUP weekend&lt;\/a&gt;. Try a combination of surfing in the waves and SUP lessons on flat water. Perfect for beginners and families.&lt;\/p&gt;\n&lt;p&gt;15th-17th&lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt; Get Ready for Summer Surf Weekend.&lt;\/a&gt; For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;22nd-24th\u00a0&lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;May 29th-June 1st June bank holiday surf weekend.\u00a0Surf, B&amp;B, c
  04-24 05:58:47.232    2140-2174/jardelcompany.bundoransurfco E/Tab4Fragment﹕ Exception caught:
      org.json.JSONException: Value [{"custom_fields":{},"comment_count":0,"tags":[],"status":"publish","excerpt":"&lt;p&gt;Check out what&amp;#8217;s happening at  Surf Co&lt;\/p&gt;\n","comment_status":"closed","date":"2014-01-09 16:43:57","type":"post","url":"http:\/\/www.bundoransurfco.com\/events\/2014-calander-of-events\/","modified":"2015-04-01 14:27:02","content":"&lt;p&gt;We open all year and have all our regular&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/beginners\/\"&gt; surf lessons &lt;\/a&gt;and also &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-stay\/lodge-packages\/\"&gt;surf and stay packages available year round&lt;\/a&gt;.&lt;\/p&gt;\n&lt;p&gt;We also have &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-camp\/\"&gt;week long surf camps&lt;\/a&gt; as well as &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/family-surf-and-stay-packages\/\"&gt;family surf and stay packages &lt;\/a&gt;all year. Below is a list of specific events. We are open for other bookings when the events below are on. We can be flexible with dates for group bookings and arrange specific packages : just call on 071-9841968 or email info@bundoransurfco.com.&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;February 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;7th-8th &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/improver-surf-weekends\/\"&gt;Improvers Surf Weekend with Surf Fit Ireland&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;13th-15th&lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-guiding\/\"&gt; Surf Guiding weekend.&lt;\/a&gt; Explore the coast with our instructors. For improver and intermediate surfers&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/singles-weekend\/\"&gt;Single Surfers Valentines Surf Weekend&lt;\/a&gt;. Meet new people, catch a few waves, have the craic. Only €79pps&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;March 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;7th-8th &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/improver-surf-weekends\/\"&gt;Improvers Surf Weekend with Surf Fit Ireland&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;13th-15th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt;Get Ready for Summer Surf Weekend&lt;\/a&gt;. For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/surf-school\/surf-guiding\/\"&gt;Surf Guiding weekend.&lt;\/a&gt; Explore the coast with our instructors. For improver and intermediate surfers&lt;\/p&gt;\n&lt;p&gt;20th-22nd &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga weekend&lt;\/a&gt;.&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;April 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;3rd-6th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/easter-surf-packages\/\"&gt;Easter Surf Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;17th-19th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt;Get Ready for Summer Surf Weekend&lt;\/a&gt;. For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;24th-26th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;May 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;1st-4th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/may-bank-holiday-surf-weekend-2\/\"&gt;May Bank Holiday Surf Weekend&lt;\/a&gt;. Surf, B&amp;B, craic and BBQ&lt;\/p&gt;\n&lt;p&gt;8th-1oth &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/sup-tours\/\"&gt;Surf and SUP weekend&lt;\/a&gt;. Try a combination of surfing in the waves and SUP lessons on flat water. Perfect for beginners and families.&lt;\/p&gt;\n&lt;p&gt;15th-17th&lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/get-ready-for-summer-surf-weekend\/\"&gt; Get Ready for Summer Surf Weekend.&lt;\/a&gt; For anyone who has not been surfing all winter and wants to get back in the water&lt;\/p&gt;\n&lt;p&gt;22nd-24th &lt;a href=\"http:\/\/www.bundoransurfco.com\/blog\/soul-surfers-yoga-weekend\/\"&gt;Surf and Yoga Weekend&lt;\/a&gt;&lt;\/p&gt;\n&lt;p&gt;May 29th-June 1st June bank holiday surf weekend. Surf, B&amp;B, craic and BBQ&lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;strong&gt;June 2015&lt;\/strong&gt;&lt;\/p&gt;\n&lt;p&gt;5th-7
  </code></pre>