{"id":74,"date":"2017-12-22T17:17:30","date_gmt":"2017-12-22T16:17:30","guid":{"rendered":"https:\/\/www.cipv6.de\/worp\/?p=74"},"modified":"2021-05-19T08:10:39","modified_gmt":"2021-05-19T07:10:39","slug":"android-get-specific-json-attribute","status":"publish","type":"post","link":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/","title":{"rendered":"Android: get specific JSON attribute"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When accessing\u00a0<a href=\"http:\/\/headers.jsontest.com\/\">http:\/\/headers.jsontest.com\/ <\/a>the following content is provided:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\"X-Cloud-Trace-Context\": \"778d633b22354c11045ece44c646dd2a\/11146751159933655926\",\n\"Accept-Language\": \"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,sv;q=0.6,la;q=0.5\",\n\"Host\": \"headers.jsontest.com\",\n\"DNT\": \"1\",\n\"User-Agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/63.0.3239.84 Safari\/537.36\",\n\"Postman-Token\": \"5851966f-f18b-cb0f-ab9c-e39ca6878d76\",\n\"Accept\": \"*\/*\",\n\"Cache-Control\": \"no-cache\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Goal is to extract the values for&nbsp; <strong>Host<\/strong> and <strong>User-Agent<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">first of all make sure that AndroidManifest.xml contains:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uses-permission android:name=\"android.permission.INTERNET\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Content of MainActivity.java:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package de.clarisweb.android.json_get_specific_attributes;\n\npublic class MainActivity extends AppCompatActivity {\npublic class DownloadTask extends AsyncTask&amp;lt; String, Void, String&amp;gt; {\n\n@Override\nprotected String doInBackground(String... urls) {\n\nString result = \"\";\nURL url;\nHttpURLConnection urlConnection= null;\n\ntry {\nurl = new URL(urls&#91;0]);\nurlConnection = (HttpURLConnection) url.openConnection();\nInputStream in = urlConnection.getInputStream();\nInputStreamReader reader = new InputStreamReader(in);\nint data = reader.read();\n\nwhile (data != -1) {\nchar current = (char) data;\nresult += current;\ndata = reader.read();\n\n}\n\nreturn result;\n\n} catch (Exception e){\n\ne.printStackTrace();\nreturn null;\n}\n}\n\n@Override\nprotected void onPostExecute(String s) {\nsuper.onPostExecute(s);\n\ntry {\nJSONObject jsonObject = new JSONObject(s);\nString hostInfo = jsonObject.getString( \"Host\");\nString userAgent = jsonObject.getString( \"User-Agent\");\nLog.i (\"Host : \", hostInfo);\nLog.i (\"User-Agent : \", userAgent);\n\n}\n\n} catch (Exception e) {\ne.printStackTrace();\n}\n\n}\n}\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\nsuper.onCreate(savedInstanceState);\nsetContentView(R.layout.activity_main);\n\nDownloadTask task = new DownloadTask();\ntask.execute(\"http:\/\/headers.jsontest.com\/\");\n\n}\n\n@Override\npublic boolean onCreateOptionsMenu(Menu menu) {\nreturn true;\n}\n\n@Override\npublic boolean onOptionsItemSelected(MenuItem item) {\nint id = item.getItemId();\nreturn super.onOptionsItemSelected(item);\n}\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">extract from Logcat shows:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>12-22 16:08:18.303 7903-7903\/de.clarisweb.android.json_get_specific_attributes I\/Content\u00a0:: headers.jsontest.com\n12-22 16:08:18.303 7903-7903\/de.clarisweb.android.json_get_specific_attributes I\/Content\u00a0:: Dalvik\/2.1.0 (Linux; U; Android 8.0.0; Android SDK built for x86 Build\/OSR1.170901.056)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When accessing\u00a0http:\/\/headers.jsontest.com\/ the following content is provided: The Goal is to extract the values for&nbsp; Host and User-Agent. first of all make sure that AndroidManifest.xml contains: Content of MainActivity.java: extract from Logcat shows:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[39,59],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-android","tag-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android: get specific JSON attribute - cipv6.de<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android: get specific JSON attribute - cipv6.de\" \/>\n<meta property=\"og:description\" content=\"When accessing\u00a0http:\/\/headers.jsontest.com\/ the following content is provided: The Goal is to extract the values for&nbsp; Host and User-Agent. first of all make sure that AndroidManifest.xml contains: Content of MainActivity.java: extract from Logcat shows:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/\" \/>\n<meta property=\"og:site_name\" content=\"cipv6.de\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-22T16:17:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-19T07:10:39+00:00\" \/>\n<meta name=\"author\" content=\"ugu5ma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ugu5ma\" \/>\n<meta name=\"twitter:site\" content=\"@ugu5ma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ugu5ma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/\"},\"author\":{\"name\":\"ugu5ma\",\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#\\\/schema\\\/person\\\/5d62b275485540be9e5e9e33d4fab86d\"},\"headline\":\"Android: get specific JSON attribute\",\"datePublished\":\"2017-12-22T16:17:30+00:00\",\"dateModified\":\"2021-05-19T07:10:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/\"},\"wordCount\":45,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#\\\/schema\\\/person\\\/5d62b275485540be9e5e9e33d4fab86d\"},\"keywords\":[\"Android\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/\",\"url\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/\",\"name\":\"Android: get specific JSON attribute - cipv6.de\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#website\"},\"datePublished\":\"2017-12-22T16:17:30+00:00\",\"dateModified\":\"2021-05-19T07:10:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/index.php\\\/2017\\\/12\\\/22\\\/android-get-specific-json-attribute\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android: get specific JSON attribute\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#website\",\"url\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/\",\"name\":\"cipv6.de\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#\\\/schema\\\/person\\\/5d62b275485540be9e5e9e33d4fab86d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.cipv6.de\\\/worp\\\/#\\\/schema\\\/person\\\/5d62b275485540be9e5e9e33d4fab86d\",\"name\":\"ugu5ma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g\",\"caption\":\"ugu5ma\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/cipv6.de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android: get specific JSON attribute - cipv6.de","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/","og_locale":"en_US","og_type":"article","og_title":"Android: get specific JSON attribute - cipv6.de","og_description":"When accessing\u00a0http:\/\/headers.jsontest.com\/ the following content is provided: The Goal is to extract the values for&nbsp; Host and User-Agent. first of all make sure that AndroidManifest.xml contains: Content of MainActivity.java: extract from Logcat shows:","og_url":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/","og_site_name":"cipv6.de","article_published_time":"2017-12-22T16:17:30+00:00","article_modified_time":"2021-05-19T07:10:39+00:00","author":"ugu5ma","twitter_card":"summary_large_image","twitter_creator":"@ugu5ma","twitter_site":"@ugu5ma","twitter_misc":{"Written by":"ugu5ma","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/#article","isPartOf":{"@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/"},"author":{"name":"ugu5ma","@id":"https:\/\/www.cipv6.de\/worp\/#\/schema\/person\/5d62b275485540be9e5e9e33d4fab86d"},"headline":"Android: get specific JSON attribute","datePublished":"2017-12-22T16:17:30+00:00","dateModified":"2021-05-19T07:10:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/"},"wordCount":45,"commentCount":1,"publisher":{"@id":"https:\/\/www.cipv6.de\/worp\/#\/schema\/person\/5d62b275485540be9e5e9e33d4fab86d"},"keywords":["Android"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/","url":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/","name":"Android: get specific JSON attribute - cipv6.de","isPartOf":{"@id":"https:\/\/www.cipv6.de\/worp\/#website"},"datePublished":"2017-12-22T16:17:30+00:00","dateModified":"2021-05-19T07:10:39+00:00","breadcrumb":{"@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cipv6.de\/worp\/index.php\/2017\/12\/22\/android-get-specific-json-attribute\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cipv6.de\/worp\/"},{"@type":"ListItem","position":2,"name":"Android: get specific JSON attribute"}]},{"@type":"WebSite","@id":"https:\/\/www.cipv6.de\/worp\/#website","url":"https:\/\/www.cipv6.de\/worp\/","name":"cipv6.de","description":"","publisher":{"@id":"https:\/\/www.cipv6.de\/worp\/#\/schema\/person\/5d62b275485540be9e5e9e33d4fab86d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cipv6.de\/worp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.cipv6.de\/worp\/#\/schema\/person\/5d62b275485540be9e5e9e33d4fab86d","name":"ugu5ma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g","caption":"ugu5ma"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/7211dd31d32612293e4228c8f880721a803dcc15211868f096ea9a8e77b6f316?s=96&d=mm&r=g"},"sameAs":["https:\/\/cipv6.de"]}]}},"_links":{"self":[{"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cipv6.de\/worp\/index.php\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}