Dictionary To Json Incorrect

Hi. this is my sample code

import Foundation

var features = [[String: Any]]()
var geo = [String: Any]()
geo["type"] = "FeatureCollection"
geo["features"] = features
let geoJson = try? JSONSerialization.data(withJSONObject: String(data: geo, encoding: .utf8)!, options: [])

Why does the error message say Cannot convert value of type '[String : Any]' to expected argument type 'Data'

I am going to use the data in the GMUGeoJSONParser(data: ...) in maps ios utils

Answered by chitgoks in 735097022

Hmm seems this was my mistake

outputting geoJson as

print(String(data: geoJson!, encoding: .utf8)!)

results in

{"features":[],"type":"FeatureCollection"}

Removed the first question instead since this is solved.

Accepted Answer

Hmm seems this was my mistake

outputting geoJson as

print(String(data: geoJson!, encoding: .utf8)!)

results in

{"features":[],"type":"FeatureCollection"}

Removed the first question instead since this is solved.

Dictionary To Json Incorrect
 
 
Q