• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Problems with JSON Array can't become String

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm making this APP for my company, but I've never used JSON with Java before, so I'm kinda lost here. After watching some tutorials, I made this function


But the response from the URL that I get is a JSON with no name,

{
 "atividade_principal": [
   {
     "text": "Portais, provedores de conteúdo e outros serviços de informação na internet",
     "code": "63.19-4-00"
   }
 ],
 "data_situacao": "01/09/2004",
 "complemento": "ANDAR 17A20 TSUL 2 17A20",
 "tipo": "MATRIZ",
 "nome": "GOOGLE BRASIL INTERNET LTDA.", //I need this part

Can someone help me, please ? This array worked like a charm, how to get "nome" from this JSON ?



If anyone needs the whole JSON: https://www.receitaws.com.br/v1/cnpj/06990590000123

That's my Log:
org.json.JSONException: Value GOOGLE BRASIL INTERNET LTDA at nome of type java.lang.String cannot be converted to JSONArray

I thank you for the help, my native forums aren't helping me
 
Ranch Hand
Posts: 151
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcus Vinícius wrote:Hello,

I'm making this APP for my company, but I've never used JSON with Java before, so I'm kinda lost here. After watching some tutorials, I made this function


That's my Log:
org.json.JSONException: Value GOOGLE BRASIL INTERNET LTDA at nome of type java.lang.String cannot be converted to JSONArray



The JSON string from the URL shows that you have an JSON object that is not an array. As immediate child there is the JSON value "nome" which has value "GOOGLE BRASIL INTERNET LTDA." and is definitely no array as the error message in the log says.

Probably, you should only retrieve the object with key "nome" and return it. following code is an untested guess:



 
Marcus Vinícius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:

Marcus Vinícius wrote:Hello,

I'm making this APP for my company, but I've never used JSON with Java before, so I'm kinda lost here. After watching some tutorials, I made this function


That's my Log:
org.json.JSONException: Value GOOGLE BRASIL INTERNET LTDA at nome of type java.lang.String cannot be converted to JSONArray



The JSON string from the URL shows that you have an JSON object that is not an array. As immediate child there is the JSON value "nome" which has value "GOOGLE BRASIL INTERNET LTDA." and is definitely no array as the error message in the log says.

Probably, you should only retrieve the object with key "nome" and return it. following code is an untested guess:





Thanks for the reply, but how would I use it in the function ? I did some search and Json is a library from Java and when I tried to use it in Android it didn't work  
 
Marcus Vinícius
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I found the solution.

In this case, the JSON that I'm looking isn't an array, so I already started wrong.

After some search and help on the web, I finished it.



And this applies to any other String in JSON, I could make a .getString("stringname"); for each String in JSON with no worries !

Thank you again !
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic