{"id":22,"date":"2021-10-28T22:30:06","date_gmt":"2021-10-28T22:30:06","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/?p=22"},"modified":"2021-10-28T22:30:06","modified_gmt":"2021-10-28T22:30:06","slug":"json-parsing-is-hard","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/2021\/10\/28\/json-parsing-is-hard\/","title":{"rendered":"JSON parsing is hard.."},"content":{"rendered":"\n<p>This week I ran into my first roadblock on this project. I was tasked with linking the barcode scanning to the Barcode Lookup API. This proved to be a challenge in 2 ways. On the scanning-side, I needed to be able to translate a barcode scan into a usable data type like a String. On the API side, I needed to be able to effectively make the API calls and parse the response data.<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>First, I took my partner&#8217;s advice to use my computer&#8217;s webcam as the camera for my Android emulator to test out the barcode scanning library. This advice worked out well and I was able to link up my webcam to the emulator through the Android Studios AVD manager. Then, I attempted to scan various barcodes I had near me. I attempted scanning a tin of Altoids, Jergen lotion, and a book. None of these resulted in a scan. The scanning simply does not return any result. Next week I plan on trouble shooting this.<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>On the API side, I struggled initially with parsing the JSON response. The JSON structure is a bit tricky since it is a large single JSON object with a &#8220;products&#8221; data. In &#8220;products&#8221; there is an array of objects, each being individual products that are relevant to the search keyword. This JSON structure required me to create a SearchResult class which contain &#8220;products&#8221; then a separate Product class which housed the data for each product in the array. I was kept receiving an error due to an array of image urls for each product. I eventually was able to deduce that this error was due to the type I was casting for this array. I had to specifically cast it as a List&lt;String&gt;() in order for the Product class to not return an error.<\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I was able to successfully print out product titles after the error was fixed. Next up, searching of products!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I ran into my first roadblock on this project. I was tasked with linking the barcode scanning to the Barcode Lookup API. This proved to be a challenge in 2 ways. On the scanning-side, I needed to be able to translate a barcode scan into a usable data type like a String. On&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/nguyjosh\/2021\/10\/28\/json-parsing-is-hard\/\">Continue reading <span class=\"screen-reader-text\">JSON parsing is hard..<\/span><\/a><\/p>\n","protected":false},"author":11596,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/users\/11596"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/posts\/22\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/nguyjosh\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}