There is a json file of the form:

{ "kind": "youtube#playlistItemListResponse", "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/sQScxznVlWgD1fXmkY5DK6q8la8\"", "nextPageToken": "CAkQAA", "prevPageToken": "CAYQAQ", "pageInfo": { "totalResults": 4348, "resultsPerPage": 3 }, 

but under certain circumstances this file may not contain one key / value pair and will look like:

 { "kind": "youtube#playlistItemListResponse", "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/LDtQl6zDAmdnv2VvMnzfjox4-9w\"", "nextPageToken": "CAMQAA", "pageInfo": { "totalResults": 4348, "resultsPerPage": 3 }, 

Question: How do I know that JSONObject contains a pair of key "prevPageToken"?

Thank.

  • one
    Did you read the documentation ? rtfm has (String name) / isNull (String name) - Yura Ivanov
  • You think I'm an idiot? Yes, I'm an idiot. Thank. :) - Erm

1 answer 1

I did this:

 dataJsonObj = new JSONObject(strJson); if (dataJsonObj.has("prevPageToken")) //Π’ΡƒΡ‚ ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ ΠΊΠΎΠ΄, Ссли истина else //Π’ΡƒΡ‚ ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ ΠΊΠΎΠ΄, Ссли лоТь 

In general, everything is elementary. Read here