Problems with Object Syntax in Json?

1

I have a problem with syntax of shoppingsObj , why are you giving this error?

  

Expected to JSON object, array or literal.

shoppingsObj = {

    "shoppings": [
        { "nome": "Bangu Shopping", "licenseKey":"0", "acessKey":"0", "secretKey":"0", "latitude1":["-22.879832"], "latitude2":["-22.877738"], "longitude1:":["-43.468601"], "longitude2:":["-43.465978"] },
        { "nome": "Boulevard Shopping Campos", "licenseKey":"0", "acessKey":"0", "secretKey":"0", "latitude1":["-21.755484"], "latitude2":["-21.753139"], "longitude1:":["-41.350870"], "longitude2:":["-41.346417"] }
    ]

 }
    
asked by anonymous 29.06.2017 / 19:29

2 answers

2
  

I'm manipulating with java for Android. I need to create an object that is the mallsObj and then do the following mallsObj.latitude []=""

If you are consuming this JSON , the valid format for your case is:

{
    "shoppings": [{
            "nome": "Bangu Shopping",
            "licenseKey": "0",
            "acessKey": "0",
            "secretKey": "0",
            "latitude1": ["-22.879832"],
            "latitude2": ["-22.877738"],
            "longitude1:": ["-43.468601"],
            "longitude2:": ["-43.465978"]
        },
        {
            "nome": "Boulevard Shopping Campos",
            "licenseKey": "0",
            "acessKey": "0",
            "secretKey": "0",
            "latitude1": ["-21.755484"],
            "latitude2": ["-21.753139"],
            "longitude1:": ["-41.350870"],
            "longitude2:": ["-41.346417"]
        }
    ]

}

But to get the result, as you have exemplified it is not possible. You have a shoppings object that contains a array , you will have to access one of the indexes or iterate over it.

An example would be:

shoppingsObj.shoppings[0].nome // retornará "Bangu Shopping"
shoppingsObj.shoppings[0].latitude1 // retornará "-22.879832"
    
29.06.2017 / 19:47
0

Try this:

{"shoppings": [
    { "nome": "Bangu Shopping", "licenseKey":"0", "acessKey":"0", "secretKey":"0", "latitude1":["-22.879832"], "latitude2":["-22.877738"], "longitude1:":["-43.468601"], "longitude2:":["-43.465978"] },
    { "nome": "Boulevard Shopping Campos", "licenseKey":"0", "acessKey":"0", "secretKey":"0", "latitude1":["-21.755484"], "latitude2":["-21.753139"], "longitude1:":["-41.350870"], "longitude2:":["-41.346417"] }
]}

Note that this json is an object that has a list of objects called shoppings so for you to change the latitude of the first mall, you would have to do:

shoppingsObj.shoppings[0].latitude = ...
    
29.06.2017 / 19:37