mardi 5 mai 2015

Parse JSON array to matrix using map

I'm using swiftyJSON.

The data looks like the following but not really, there are about 700,000 elements.

{
    "data": [
        [
            "one",
            "steak",
            -0.234
        ],
        [
            "cat",
            "pizza",
            1.9812
        ]
    ]
}

Currently I'm using this

let jsonArray:[JSON] = json["data"].arrayValue
for ( i=0; i<jsonArray.count; i++ )//number of data points
{
  A.append(jsonArray[i][0].string! )
  B.append(jsonArray[i][1].string! )
  X.append(jsonArray[i][2].float! )
}

but it is slow, I'd like to use map to speed things up to create individual arrays like shown or a M x N matrix. Or how would I put this into a struct?

Aucun commentaire:

Enregistrer un commentaire