title: Parsing json objects only
body: <p><img src="https://i.stack.imgur.com/q5PeT.png" alt="enter image description here">I am having a lot of trouble with this. I have a json array that i have parsed which works great. I have another webpage for a single user i am trying to parse. here is the php. its valid json.</p>
  
  <pre><code>{
      "userURL": "http://forum.example.com.php?u=426561",
      "userId": "426561",
      "forumName": "example name",
      "totalPosts": "19787",
      "postsPerDay": "8.11",
      "totalThanks": "40585",
      "joinDate": "2007-02-20",
      "yearsJoined": "6",
      "referrals": "17",
      "friendCount": "61",
      "recognizedDeveloper": "1",
      "recognizedContributor": "0",
      "recognizedThemer": "0",
      "moderator": "0",
      "recognizedEliteDeveloper": "0",
      "romCount": "100",
      "kernelCount": "1",
      "tutorialCount": "0",
      "modCount": "21",
      "themeCount": "0",
      "originalAppCount": "0",
      "toolkitCount": "0",
      "scriptCount": "0",
      "sOffCount": "0",
      "recoveryCount": "0",
      "score": "687",
      "rank": "1 out of 122"
  }
  </code></pre>
  
  <p>here is my parser class.</p>
  
  <pre><code>public class JSONParser1 {
  
  static InputStream is = null;
  static JSONObject jObj = null;
  static String json = "";
  
  // constructor
  public JSONParser1() {
  
  }
  
  public JSONObject getJSONFromUrl(String url) {
  
      // Making HTTP request
      try {
          // defaultHttpClient
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(url);
  
          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity httpEntity = httpResponse.getEntity();
          is = httpEntity.getContent();           
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      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();
          json = sb.toString();
      } catch (Exception e) {
          Log.e("Buffer Error", "Error converting result " + e.toString());
      }
  
      // try parse the string to a JSON object
      try {
          jObj = new JSONObject(json);
      } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
      }
  
      // return JSON String
      return jObj;
  
  }}
  </code></pre>
  
  <p>here I am just trying to  grab one of the values. </p>
  
  <pre><code>public class GetScore extends Activity {
  
  
  private static String url = "http://example.com"
  
  
  private static String TAG_NAME = "forumName";
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       setContentView(R.layout.getscore);
  
      JSONParser1 jParser1 = new JSONParser1();
      JSONObject json = jParser1.getJSONFromUrl(url);
  
      try {
          json = new JSONObject(TAG_NAME);
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
    //get nickname
     try {
      json.getString("forumName");
  } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
    ///.... get other value for object
  }   
  }
  </code></pre>
  
  <p>also How would i tie this to a resourse ID? 
  any help would be greatly appreciated.</p>
  
  <pre><code>public class GetScore extends Activity {
  
  private static String url = "http://example.com"
  private static String TAG_NAME = "forumName";
  private JSONParser1 jParser1 ;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.getscore);
  
      jParser1 = new JSONParser1();
      new GetJSONTask().execute(url);
  
  
  }
  
  
      class GetJSONTask extends AsyncTask&lt;String, Void, JSONObject&gt; {
  
         private Exception exception;
  
  
  
  
  
  protected JSONObject doInBackground(String... urls) {
      try {
          JSONParser1 jParser = new JSONParser1();
          return jParser.getJSONFromUrl(urls[0]);
      } catch (Exception e) {
          return null;
      }
  }
  
  
  
  
  protected void onPostExecute(JSONObject json) {
      // do all the parsing here:
  
      //get nickname
      try {
          // You then reset the same variable here
          // the previous object is now lost, or if it throws an exception,
          // the previously set value remains (whether null or not)
          json = new JSONObject(TAG_NAME);
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      // This object could easily be null, or could be valid if the previous
      // call failed
      try {
          json.getString("forumName");
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }}}}
  </code></pre>