-2

I am currently working on a way to parse the output of a section of a MySQL query using Groovy's JsonSlurper.

I am trying to pull the LAT and LONG values from this query.

The query with the Json included reads fine into the database, with the expected values being returned, however, when I try and parse this Json in my JsonSlurper I get a java Missing Method exception, which complains about the parseText(). The error recommends parseText as a solution, although this is what is being used.

The error is as follows: groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parseText() is applicable for argument types: (java.util.ArrayList)

My code is as follows:

The section of the query which produces the json is as follows:

 SELECT   concat('{Address:"',n.address,'",LAT:"'map.details,'",LONG:"'map.details'"}') as list FROM table

I then call the list in my JsonSlurper method, which is being populated as a database field in the application:

def result = new JsonSlurper().parseText(table.list)
def latitude = result.get("LAT")
def longitude = result.get("LONG")

println latitude
println longitude

I then plan on populating these fields in a web page, but I cannot do this until I am able to return them from the parse. The latitude and longitude values are integers, although they are parsed as strings.

AD26891
  • 73
  • 2
  • 11
  • The error message is very clear. You pass an `ArrayList` instead of `String` to `parseText` method. – Opal Apr 15 '15 at 19:00

1 Answers1

0

The result of your query is a list of JSON strings, even if there is only one element. Use

new JsonSlurper().parseText(table.list.first())
Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43