SlideShare uma empresa Scribd logo
1 de 1
Answer this following question about a JSON response and parsing it
The following acre enshot shows the JSON response from a Geographic API. Parse this response
to print the Latitude and Longitude.
Solution
There are many ways to parse the json and print the values. Some of the main json utilities
available in java are : Google's gson, and Jackson, otherwise we can use the plain org.json class
available in java.
Parsing can be done like below for getting all the latitude and longitude:
JSONObject result_set = new JSONObject("result_set");
JSONArray results = result_set.getJSONArray("results");
for (int i = 0; i < results.length(); i++)
{
JSONObject result = results.getJSONObject(i);
JSONObject geocode = result.getJSONObject(i);
String latitude = geocode.getString("latitude");
String longitude = geocode.getString("longitude");
}

Mais conteúdo relacionado

Semelhante a Answer this following question about a JSON response and parsing it Th.docx

JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
Laurence Svekis ✔
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
Faysal Shaarani (MBA)
 

Semelhante a Answer this following question about a JSON response and parsing it Th.docx (20)

JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
 
Android training day 5
Android training day 5Android training day 5
Android training day 5
 
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
All About JSON and ClickHouse - Tips, Tricks and New Features-2022-07-26-FINA...
 
Json
JsonJson
Json
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
Don’t Get Lost in Translation for Serializing Data Structures
Don’t Get Lost in Translation for Serializing Data StructuresDon’t Get Lost in Translation for Serializing Data Structures
Don’t Get Lost in Translation for Serializing Data Structures
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
 
JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesome
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
 
Json vs Gson vs Jackson
Json vs Gson vs JacksonJson vs Gson vs Jackson
Json vs Gson vs Jackson
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
mobl
moblmobl
mobl
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
quick json parser
quick json parserquick json parser
quick json parser
 

Mais de rtodd665

Mais de rtodd665 (18)

As related to the --Virtue Matrix-- article- what are examples of at l.docx
As related to the --Virtue Matrix-- article- what are examples of at l.docxAs related to the --Virtue Matrix-- article- what are examples of at l.docx
As related to the --Virtue Matrix-- article- what are examples of at l.docx
 
Arrange the following ions in order of increasing ionic radius- iodide.docx
Arrange the following ions in order of increasing ionic radius- iodide.docxArrange the following ions in order of increasing ionic radius- iodide.docx
Arrange the following ions in order of increasing ionic radius- iodide.docx
 
Arro hits Apple -ne here to search 40 5 Solutiona) Initial Horizontal.docx
Arro hits Apple -ne here to search 40 5 Solutiona) Initial Horizontal.docxArro hits Apple -ne here to search 40 5 Solutiona) Initial Horizontal.docx
Arro hits Apple -ne here to search 40 5 Solutiona) Initial Horizontal.docx
 
Arrange the following elements in order of increasing electronegativit.docx
Arrange the following elements in order of increasing electronegativit.docxArrange the following elements in order of increasing electronegativit.docx
Arrange the following elements in order of increasing electronegativit.docx
 
Arrange reducing agents by increasing strength (weakest to strongest).docx
Arrange reducing agents by increasing strength (weakest to strongest).docxArrange reducing agents by increasing strength (weakest to strongest).docx
Arrange reducing agents by increasing strength (weakest to strongest).docx
 
Are cell phones positive----negative----both-Solution1) Cell phones co.docx
Are cell phones positive----negative----both-Solution1) Cell phones co.docxAre cell phones positive----negative----both-Solution1) Cell phones co.docx
Are cell phones positive----negative----both-Solution1) Cell phones co.docx
 
Answer questions 1-5 pleaseSolution1) In Diels Alder reaction diene is.docx
Answer questions 1-5 pleaseSolution1) In Diels Alder reaction diene is.docxAnswer questions 1-5 pleaseSolution1) In Diels Alder reaction diene is.docx
Answer questions 1-5 pleaseSolution1) In Diels Alder reaction diene is.docx
 
Application programming interface (API)SolutionWhat is an API- An appl.docx
Application programming interface (API)SolutionWhat is an API- An appl.docxApplication programming interface (API)SolutionWhat is an API- An appl.docx
Application programming interface (API)SolutionWhat is an API- An appl.docx
 
Answer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docxAnswer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docx
 
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docxapp-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
 
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docxAnswer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
 
Anser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docxAnser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docx
 
Any help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docxAny help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docx
 
Assume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docxAssume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docx
 
Assume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docxAssume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docx
 
Assume that the amounts of the company Oslo Company prepared the f.docx
Assume that the amounts of the company    Oslo Company  prepared the f.docxAssume that the amounts of the company    Oslo Company  prepared the f.docx
Assume that the amounts of the company Oslo Company prepared the f.docx
 
Assume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docxAssume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docx
 
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docxAssume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Answer this following question about a JSON response and parsing it Th.docx

  • 1. Answer this following question about a JSON response and parsing it The following acre enshot shows the JSON response from a Geographic API. Parse this response to print the Latitude and Longitude. Solution There are many ways to parse the json and print the values. Some of the main json utilities available in java are : Google's gson, and Jackson, otherwise we can use the plain org.json class available in java. Parsing can be done like below for getting all the latitude and longitude: JSONObject result_set = new JSONObject("result_set"); JSONArray results = result_set.getJSONArray("results"); for (int i = 0; i < results.length(); i++) { JSONObject result = results.getJSONObject(i); JSONObject geocode = result.getJSONObject(i); String latitude = geocode.getString("latitude"); String longitude = geocode.getString("longitude"); }