0

I am requesting some data from Facebook over JAVA in android and sending it to the server:

Address[addressLines=[0:"Königspl., 86150 Augsburg, Germany"],feature=Königsplatz,admin=Bayern,sub-admin=Schwaben,locality=Augsburg,thoroughfare=Königsplatz,postalCode=86150,countryCode=DE,countryName=Germany,hasLatitude=true,latitude=48.366384499999995,hasLongitude=true,longitude=10.8943626,phone=null,url=null,extras=null]

I don't know what exactly this is, JAVA Object or I don't know..

I already tried: $array = json_decode($data, true); and it returns NULL

What is it and how do I convert it to PHP Array?

EDIT:

This is the JAVA (actually kotlin) code I use to generate the data:

val geocoder = Geocoder(this, Locale.ENGLISH)
try {
    val addresses = geocoder.getFromLocation(48.366512, 10.894446, 1)

    if (addresses != null)
    {
        val returnedAddress = addresses[0]
        val strReturnedAddress = StringBuilder("Address:\n")
        for (i in 0 until returnedAddress.maxAddressLineIndex) {
            strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n")
        }

        geocoderStuff = returnedAddress.toString()

    } else
    {
        // NO ADDRESS
    }
} catch (e: IOException) {
    e.printStackTrace()
}

And this how I send it:

                val params = RequestParams()
                params.put("geocoder", geocoderStuff)
                letsDoSomeNetworking(params)

private fun letsDoSomeNetworking(params: RequestParams) {

        // AsyncHttpClient belongs to the loopj dependency.
        val client = AsyncHttpClient()

        client.get("http://www.bla.com/android/fb_access.php", params, object : JsonHttpResponseHandler()
        {
            override fun onSuccess(statusCode: Int, headers: Array<Header>?, response: JSONObject?)
            {
                // success
            }

            override fun onFailure(statusCode: Int, headers: Array<Header>?, e: Throwable, response: JSONObject?)
            {
                // error
            }
        })
    }
11
  • do you want to convert into PHP Array using Java? Commented Aug 16, 2018 at 6:57
  • I think I wouldn't be able to send it as GET to the server that easy then, I'm a beginner in android/JAVA :) Commented Aug 16, 2018 at 6:58
  • can you post the java code that is used for sending data to server? Commented Aug 16, 2018 at 6:58
  • Ok I edited the question Commented Aug 16, 2018 at 7:09
  • try to use $_GET['geocoder'] on json_decode. see if it works or not. Commented Aug 16, 2018 at 7:11

1 Answer 1

1

The solution is to use gson library on JAVA/Kotlin side after getting the data:

        val returnedAddress = addresses[0]
        val strReturnedAddress = StringBuilder("Address:\n")
        for (i in 0 until returnedAddress.maxAddressLineIndex) {
            strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n")
        }

        val gson = Gson() // HERE
        val json = gson.toJson(returnedAddress) // HERE

        geocoderStuff = json
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.