json


Type “Any” has no subscript members while parsing JSON


func parseResponseData(response: AnyObject) {
if let feedData = response["feed"] as? [String: Any]{
let entryArray = feedData["entry"] as Any
if let entry = entryArray as? [Any]{
for object in entry{
print(object)
let appName = object["category"] as [String: Any] // Error: Type "Any" has no subscript members.
}
}
}
}
I am not able to parse the response because of this error, any clue how to resolve this.
JSON response
try this, entryArray is an array of String : Any
func parseResponseData(response: AnyObject) {
if let feedData = response["feed"] as? [String: Any]{
let entryArray = feedData["entry"] as Any
if let entry = entryArray as? [[String: Any]] {
for object in entry {
print(object)
let appName = object["category"] as? [String: Any]
}
}
}
}
You have to tell the compiler the actual types of all subscripted collection types, Any is not sufficient.
It's helpful to use a type alias for the JSON dictionary
typealias JSONDictionary = [String:Any]
func parseResponseData(response: Any) {
if let feedData = response["feed"] as? JSONDictionary,
let entryArray = feedData["entry"] as? [JSONDictionary] {
for object in entryArray {
print(object)
if let category = object["category"] as? JSONDictionary {
print(category)
}
}
}
}

Related Links

Facebook Graph API inbox messages with no comments array
extjs nested model
wikipedia API: parse a table as JSON?
give json data to jqGrid view once
How do I update one controller with data from another controller with a service in angular?
ExtJS Specify the existing date format for conversion
Binding viewmodel with knockoutjs mapping
Bug in twitteR and sentiment analysis code [closed]
What's wrong with this JSON object?
Using ModelCompanion's fromJSON method in Play application throws a NoSuchMethodException
How do I parse this JSON-string in Go?
Sencha store and model set up for use with Json
Grails rendering JSON from domain list weird behaviour
properties file to json [closed]
Action composition in Play framework with Java
Posting form data as Json using Knockout JS/ JQuery

Categories

HOME
sharepoint
security
freepascal
ncurses
deep-linking
parse-server
phpstorm
search-engine
specflow
propertygrid
value
tizen-wearable-sdk
bro
browserify
onenote-api
structuremap
constructor
octopus-deploy
vuex
unity2d
cockroachdb
tee
viber
netezza
cross-platform
anychart
dspic
servicemix
npm-install
rhmap
lync-2013
upnp
i3
mayavi
lmdb
node-horseman
gettext
google-guava-cache
zero
declare
brute-force
infusionsoft
restful-url
stdclass
react-native-router-flux
taglib
bids
webdatagrid
adler32
rsqlite
pdflib
c#-interactive
vst
bacnet
pagekit
soda
spring-repositories
distribute
axes
web-essentials
galaxy
lemoon
self-hosting
hyperthreading
registrykey
connection-reset
team-build
manjaro
ubercart
robocode
google-earth-plugin
level
zipalign
openkinect
sanitization
sqljdbc
modeshape
image-zoom
dynamics-ax-2009
symphony-cms
pascals-triangle
mvs
socketstream
nintendo
nssavepanel
serp
squeel
rtsp-client

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App