I have JSON file in response.
(
{
location = {
lat = "23.0429226";
lng = "72.51406419999999";
};
"location_type" = APPROXIMATE;
viewport = {
northeast = {
lat = "23.0531899";
lng = "72.5300716";
};
southwest = {
lat = "23.0326545";
lng = "72.4980568";
};
};
}
)
To parse lat and long of location i have write this code. but when i am converting that value into float value it is giving me error like this.
Blockquote
-[__NSArrayI floatValue]: unrecognized selector sent to instance 0xdd2d080
2013-11-21 19:31:15.602 App[3515:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI floatValue]: unrecognized selector sent to instance 0xdd2d080'
*** First throw call stack:
(
0 CoreFoundation 0x0328c5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0300f8b6 objc_exception_throw + 44
2 CoreFoundation 0x03329903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0327c90b ___forwarding___ + 1019
4 CoreFoundation 0x0327c4ee _CF_forwarding_prep_0 + 14
5 App 0x000885d8 __55-[WorkLocationViewController sendLatLongRequestAction:]_block_invoke + 744
6 App 0x0002901e -[ASIHTTPRequest reportFinished] + 222
7 libobjc.A.dylib 0x0302181f -[NSObject performSelector:withObject:] + 70
8 Foundation 0x02c64c18 __NSThreadPerformPerform + 285
9 CoreFoundation 0x032158af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
10 CoreFoundation 0x0321523b __CFRunLoopDoSources0 + 235
11 CoreFoundation 0x0323230e __CFRunLoopRun + 910
12 CoreFoundation 0x03231b33 CFRunLoopRunSpecific + 467
13 CoreFoundation 0x0323194b CFRunLoopRunInMode + 123
14 GraphicsServices 0x0462b9d7 GSEventRunModal + 192
15 GraphicsServices 0x0462b7fe GSEventRun + 104
16 UIKit 0x01d8294b UIApplicationMain + 1225
17 App 0x000040fd main + 141
18 libdyld.dylib 0x037fb725 start + 0
19 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
My code is:
NSDictionary *geo=[res valueForKey:#"geometry"];
NSDictionary *loc=[geo valueForKey:#"location"];
NSLog(#"latitiude is%#",[loc valueForKey:#"lat"]);
NSLog(#"lon is %#",[loc valueForKey:#"lng"]);
//NSLog(#"float value is%f",[[loc valueForKey:#"lat"] floatValue]);
NSString *str=[loc valueForKey:#"lat"];
NSLog(#"string is %#",str);
NSString *str1=[loc valueForKey:#"lng"];
workCoordinate.latitude=[str floatValue];
workCoordinate.longitude=[str1 floatValue];
and in log string is print like this:
2013-11-21 19:31:15.599 App[3515:a0b] latitiude is(
"23.0429226"
)
2013-11-21 19:31:15.599 App[3515:a0b] lon is (
"72.51406419999999"
)
2013-11-21 19:31:15.600 App[3515:a0b] string is (
"23.0429226"
Here is JSON which I am getting in response.
{
results = (
{
"address_components" = (
{
"long_name" = "Judges Bunglow Police Chawky";
"short_name" = "Judges Bunglow Police Chawky";
types = (
establishment
);
},
{
"long_name" = "Satya Marg";
"short_name" = "Satya Marg";
types = (
route
);
},
{
"long_name" = Bodakdev;
"short_name" = Bodakdev;
types = (
sublocality,
political
);
},
{
"long_name" = Ahmedabad;
"short_name" = Ahmedabad;
types = (
locality,
political
);
},
{
"long_name" = Ahmedabad;
"short_name" = Ahmedabad;
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = GJ;
"short_name" = GJ;
types = (
"administrative_area_level_1",
political
);
},
{
"long_name" = India;
"short_name" = IN;
types = (
country,
political
);
},
{
"long_name" = 380015;
"short_name" = 380015;
types = (
"postal_code"
);
}
);
"formatted_address" = "Judges Bunglow Police Chawky, Satya Marg, Bodakdev, Ahmedabad, GJ 380015, India";
geometry = {
bounds = {
northeast = {
lat = "23.0369726";
lng = "72.51639879999999";
};
southwest = {
lat = "23.03688";
lng = "72.5162807";
};
};
location = {
lat = "23.0368868";
lng = "72.5163184";
};
"location_type" = APPROXIMATE;
viewport = {
northeast = {
lat = "23.0382752802915";
lng = "72.51768873029151";
};
southwest = {
lat = "23.0355773197085";
lng = "72.5149907697085";
};
};
};
"partial_match" = 1;
types = (
police,
establishment
);
}
);
status = OK;
}
If you look carefully at your NSLog results, you'll see that your line:
NSString *str=[loc valueForKey:#"lat"];
NSLog(#"string is %#",str);
is returning
2013-11-21 19:31:15.600 appname[3515:a0b] string is (
"23.0429226"
)
Rather than what you wanted
2013-11-21 19:31:15.600 appnane[3515:a0b] string is "23.0429226"
Those parentheses are telling you that valueForKey is returning an NSArray, not a NSString. Two solutions, first, you could just grab the first object from that array:
NSArray *latArray=[loc valueForKey:#"lat"];
NSString *str=latArray[0]
NSLog(#"string is %#",str);
Alternatively, you might to use objectForKey rather than valueForKey. Unfortunately, your code snippet does not make it clear what nested array of dictionary objects you logged at the top of your question (e.g. I don't see any reference to #"geometry"). But let's say it was results. If that was the case, you might do something like:
for (NSDictionary *dictionary in results) {
NSDictionary *location = dictionary[#"location"]; // or [dictionary objectForKey:#"location"];
NSString *latString = location[#"lat"]; // or [location objectForKey:#"lat"];
NSString *lngString = location[#"lng"]; // or [location objectForKey:#"lng"];
CGFloat lat = [latString floatValue];
CGFloat lng = [lngString floatValue];
}
In your updated question, you provide a more complete NSLog of the resulting object you received from your JSON parser. For example, let's assume that the NSDictionary you logged was called jsonObject. You could then extract that latitude and longitude via:
NSString *status = jsonObject[#"status"];
NSArray *results = jsonObject[#"results"];
NSDictionary *result = results[0]; // let's grab the first result
NSArray *addressComponents = result[#"address_components"];
NSString *formattedAddress = result[#"formatted_address"];
NSDictionary *geometry = result[#"geometry"];
NSNumber *partialMatch = result[#"partial_match"];
NSArray *types = result[#"types"];
NSDictionary *location = geometry[#"location"];
NSString *latitudeString = location[#"lat"];
NSString *longitudeString = location[#"lng"];
CGFloat latitude = [latitudeString floatValue];
CGFloat longitude = [longitudeString floatValue];
Related
I am trying to populate an array of NSObject custom class but when I insert the data I receive an error: [Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0
Action that calls the class
#IBAction func selecionarFotosButtonClicked(_ sender: NSButton) {
let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = false
panel.allowsMultipleSelection = true
panel.canCreateDirectories = false
panel.allowedFileTypes = NSImage.imageTypes
panel.beginSheetModal(for: view.window!) { (result) in
if result.rawValue == NSFileHandlingPanelOKButton {
for url in panel.urls {
let fotoNSImage = NSImage(byReferencing: url)
let fotoNSImageRedim = Ferramentas.redimensionaNSImage(imagem: fotoNSImage, tamanho: NSSize(width: 200, height: 200))
let fotoNSImageRep = NSBitmapImageRep(data: (fotoNSImageRedim.tiffRepresentation)!)
let fotoNSImagePng = fotoNSImageRep?.representation(using: NSBitmapImageRep.FileType.png, properties: [:])
//let fotoProduto = FotoProduto(foto: PFFile(data: fotoNSImagePng!)!, categorias: [])
let fotoProduto = FotoProduto()
fotoProduto.foto = PFFile(data: fotoNSImagePng!)
fotoProduto.categorias = []
fotoProduto.imagemCapa = false
self.projeto?.fotos = [FotoProduto]()
self.projeto?.fotos.append(fotoProduto)
}
self.verificaCapaDefinida()
if !self.capaDefinida {
let indiceImagem = IndexPath(item: 0, section: 0)
self.definirImagemCapa(indice: indiceImagem, limparSelecao: true)
} else {
self.fotosProjetoCollectionView.deselectAll(self)
self.fotosProjetoCollectionView.reloadData()
}
}
}
}
FotoProduto Class
import Cocoa
import Parse
class FotoProduto: NSObject {
#NSManaged var foto: PFFile?
#NSManaged var categorias: [String]
#NSManaged var imagemCapa: Bool
override init() {
super.init()
}
}
Here is the complete error:
2017-09-21 07:13:58.074278-0400 Wood Factory -
Gerenciador[1241:101761] -[Wood_Factory___Gerenciador.FotoProduto
setFoto:]: unrecognized selector sent to instance 0x6080000055a0
2017-09-21 07:13:58.478223-0400 Wood Factory -
Gerenciador[1241:101761] [General]
-[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0 2017-09-21
07:13:58.482745-0400 Wood Factory - Gerenciador[1241:101761] [General]
( 0 CoreFoundation 0x00007fff930452cb
exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffa7e5d48d objc_exception_throw + 48 2 CoreFoundation
0x00007fff930c6f04 -[NSObject(NSObject) doesNotRecognizeSelector:] +
132 3 CoreFoundation 0x00007fff92fb7755
___forwarding_ + 1061 4 CoreFoundation 0x00007fff92fb72a8 _CF_forwarding_prep_0 + 120 5 Wood Factory -
Gerenciador 0x000000010003e68c
_T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_
+ 1948 6 Wood Factory - Gerenciador 0x000000010003ee78 _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_TA
+ 88 7 Wood Factory - Gerenciador 0x000000010000ba01 _T0So13NSApplicationC13ModalResponseVIxy_ADIyBy_TR + 49 8 AppKit 0x00007fff911b78b9 -[NSSavePanel _didEndSheet:returnCode:contextInfo:]
+ 95 9 AppKit 0x00007fff90d25b84 -[NSWindow _endWindowBlockingModalSession:returnCode:] + 308 10 AppKit 0x00007fff911ba073 -[NSSavePanel
ok:] + 461 11 libsystem_trace.dylib 0x00007fffa89753a7
_os_activity_initiate_impl + 53 12 AppKit 0x00007fff91232721 -[NSApplication(NSResponder) sendAction:to:from:] +
456 13 AppKit 0x00007fff90d16cc4
-[NSControl sendAction:to:] + 86 14 AppKit 0x00007fff90d16bec __26-[NSCell _sendActionFrom:]_block_invoke + 136
15 libsystem_trace.dylib 0x00007fffa89753a7
_os_activity_initiate_impl + 53 16 AppKit 0x00007fff90d16b44 -[NSCell _sendActionFrom:] + 128 17 AppKit
0x00007fff90d59539 -[NSButtonCell _sendActionFrom:] + 98 18
libsystem_trace.dylib 0x00007fffa89753a7
_os_activity_initiate_impl + 53 19 AppKit 0x00007fff90d15426 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] +
2481 20 AppKit 0x00007fff90d59272
-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798 21 AppKit 0x00007fff90d13ddb -[NSControl
mouseDown:] + 832 22 AppKit
0x00007fff913ae24f -[NSWindow(NSEventRouting)
_handleMouseDownEvent:isDelayedEvent:] + 6341 23 AppKit 0x00007fff913aaa6c -[NSWindow(NSEventRouting)
_reallySendEvent:isDelayedEvent:] + 1942 24 AppKit 0x00007fff913a9f0a -[NSWindow(NSEventRouting) sendEvent:] + 541 25
AppKit 0x00007fff9122e681
-[NSApplication(NSEvent) sendEvent:] + 1145 26 AppKit 0x00007fff90aa9427 -[NSApplication run] + 1002 27 AppKit
0x00007fff90a73e0e NSApplicationMain + 1237 28 Wood Factory -
Gerenciador 0x000000010005038d main + 13 29 libdyld.dylib
0x00007fffa8743235 start + 1 )
The solution was create a subclass of PFObject.
import Cocoa
import Parse
class FotoProduto: PFObject, PFSubclassing {
#NSManaged var foto: PFFile?
#NSManaged var categorias: [String]
#NSManaged var imagemCapa: Bool
override init() {
super.init()
}
init(foto: PFFile, categorias: [String]) {
super.init()
self.foto = foto
self.categorias = categorias
self.imagemCapa = false
}
static func parseClassName() -> String {
return "FotoProduto"
}
}
which pulls data from and reformats it.
Promise = require "bluebird"
request = Promise.promisify require "request"
moment = require "moment"
cdn = require('config').server.cloudFrontDomain
toTitleCase = require "titlecase"
exports.getStocks = (path) ->
return new Promise (resolve, reject) ->
request path
.then (body) ->
germanStock = []
germanStocks = JSON.parse body.body
germanStocks.forEach (stock) ->
obj = {}
this.parsePart = (remaining) ->
value = remaining.value
dashIndex = value.lastIndexOf '-'
if dashIndex != -1
remaining.value = value.substring 0, dashIndex - 1
return value.substring(dashIndex + 1).trim()
else
return ''
remaining =
value: stock.name
size = parsePart remaining
colour = parsePart remaining
name = remaining.value
sku = stock.sku
styleId = sku.split(/-/)[0]
colorcode = /^(.*)-(.*)([0-9])$/.exec(sku)?[2]
bgStyle = "url(//#{cdn}/assets/product_shots/thumbs/#{styleId}-#{colorcode}.jpg)"
obj.id = sku
obj.name = name
obj.colorUrl = bgStyle
obj.colour = toTitleCase(colour.toLowerCase())
obj.size = size
obj.stock = stock.stock
obj.inProduction = ''
obj.office = 'DE'
stock.preorders.forEach (i, idx) ->
date = moment(i.date).format('DD-MM-YYYY')
if idx != stock.preorders.length - 1
obj.inProduction = obj.inProduction.concat i.amount + ' due on ' + date + ', '
else
obj.inProduction = obj.inProduction.concat i.amount + ' due on ' + date
germanStock.push obj
resolve germanStock
.catch (err) ->
reject err
where my data is like:
{
"id":1,
"stamp":"2014-09-25T12:55:30Z",
"name":" MENS T-SHIRT - BRIGHT BLUE - XS",
"sku":"SS01-BB0",
"stock":81,
"active":true,
"preorders":[
{
"id":92549,
"amount":160,
"date":"2016-06-19T22:00:00Z"
},
{
"id":92549,
"amount":200,
"date":"2016-06-19T22:00:00Z"
},
{
"id":92549,
"amount":1000,
"date":"2016-06-21T22:00:00Z"
}
],
"discountMatrix":0.0,
"stockNormalized":81,
"preOrdersSum":1360
},
{
"id":2,
"stamp":"2014-09-25T12:55:30Z",
"name":" MENS T-SHIRT - BRIGHT BLUE - S",
"sku":"SS01-BB1",
"stock":339,
"active":true,
"preorders":[
{
"id":92551,
"amount":240,
"date":"2016-06-19T22:00:00Z"
},
{
"id":92438,
"amount":160,
"date":"22016-06-19T22:00:00Z"
}
],
"discountMatrix":0.0,
"stockNormalized":339,
"preOrdersSum":400
},
what is the correct way to group each preorders quantity that is on the same date, so that instead of getting:
160 due on 19-06-2016, 200 due on 19-06-2016, 1000 due on 21-06-2016
i get 360 due on 19-06-2016, 1000 due on 21-06-2016
any advice much appreciated.
You could just use an object with the date as key and the total amount for the date as value.
For each preorder, add it's amount at it's date index in this object. At the end of the iteration print the content of the object:
moment = require "moment"
data = [
{
id:1
stamp: "2014-09-25T12:55:30Z"
name: " MENS T-SHIRT - BRIGHT BLUE - XS"
sku: "SS01-BB0"
stock:81
active:true
preorders:[
{
id:92549
amount:160
date: "2016-06-19T22:00:00Z"
}
{
id:92549
amount:200
date: "2016-06-19T22:00:00Z"
}
{
id:92549
amount:1000
date: "2016-06-21T22:00:00Z"
}
]
discountMatrix:0.0
stockNormalized:81
preOrdersSum:1360
}
]
obj = {}
obj.inProduction = ""
amountByDate = {}
# for each document in your data
for doc in data
# for each preorder in your document
for preorder in doc.preorders
# add it's amount in the index equals to it's date
if amountByDate[preorder.date]
amountByDate[preorder.date] += preorder.amount
else
# or create the index with the value if it doesn't exist
amountByDate[preorder.date] = preorder.amount
for date, amount of amountByDate
if obj.inProduction != ""
obj.inProduction = obj.inProduction.concat ", #{amount} due on #{moment(date).format('DD-MM-YYYY')}"
else
obj.inProduction = obj.inProduction.concat "#{amount} due on #{moment(date).format('DD-MM-YYYY')}"
console.log obj.inProduction
Result:
360 due on 20-06-2016, 1000 due on 22-06-2016
I tried to write "Detecting When A User Blows Into The Mic" in Swift and I am receiving this error: "unrecognized selector sent to instance 0x78737d70"
This is my code:
import Foundation
import UIKit
import AVFoundation
import CoreAudio
class ViewController: UIViewController {
// #IBOutlet weak var mainImage: UIImageView!
var recorder: AVAudioRecorder!
var levelTimer = NSTimer()
var lowPassResults: Double = 0.0
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL.fileURLWithPath("dev/null")
//numbers are automatically wrapped into NSNumber objects, so I simplified that to [NSString : NSNumber]
var settings : [NSString : NSNumber] = [AVSampleRateKey: 44100.0, AVFormatIDKey: kAudioFormatAppleLossless, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.Max.rawValue]
var error: NSError?
// mainImage?.image = UIImage(named: "flyForReal.png");
recorder = AVAudioRecorder(URL:url, settings:settings, error:&error)
/*
sending prepareToRecord message -> activate metering -> recording -> NSTimer object that fires once ever 0.03 seconds repeatedly. Every time it fires, it sends a message to the listenForBlow function
*/
if((recorder) != nil){
recorder.prepareToRecord()
recorder.meteringEnabled = true
recorder.record()
levelTimer = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: Selector("levelTimerCallback"), userInfo: nil, repeats: true)
}
else{
NSLog("%#", "Error");
}
}
func levelTimerCallback(timer:NSTimer) {
recorder.updateMeters()
let ALPHA: Double = 0.05
var peakPowerForChannel = pow(Double(10), (0.05 * Double(recorder.peakPowerForChannel(0))))
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
if(lowPassResults > 0.95){
NSLog("#Mic blow detected");
}
NSLog("#Average input: %f Peak input: %f Low pass results: %f", recorder.averagePowerForChannel(0), recorder.peakPowerForChannel(0), lowPassResults);
}
}
I don't know how to fix it. Thanks ahead!
These are the errors I get:
2015-07-05 13:22:11.210 Reaktion[7797:471551] -[Reaktion.ViewController levelTimerCallback]: unrecognized selector sent to instance 0x78737d70
2015-07-05 13:22:11.219 Reaktion[7797:471551] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [Reaktion.ViewController levelTimerCallback]: unrecognized selector sent to instance 0x78737d70'
*** First throw call stack:
(
0 CoreFoundation 0x00586746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01f87a97 objc_exception_throw + 44
2 CoreFoundation 0x0058e705 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x004d5287 ___forwarding___ + 1047
4 CoreFoundation 0x004d4e4e _CF_forwarding_prep_0 + 14
5 Foundation 0x0098d6d9 __NSFireTimer + 97
6 CoreFoundation 0x004df866 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
7 CoreFoundation 0x004df1ed __CFRunLoopDoTimer + 1309
8 CoreFoundation 0x0049d54a __CFRunLoopRun + 2090
9 CoreFoundation 0x0049ca5b CFRunLoopRunSpecific + 443
10 CoreFoundation 0x0049c88b CFRunLoopRunInMode + 123
11 GraphicsServices 0x03d172c9 GSEventRunModal + 192
12 GraphicsServices 0x03d17106 GSEventRun + 104
13 UIKit 0x00daa106 UIApplicationMain + 1526
14 Reaktion 0x00071034 main + 180
15 libdyld.dylib 0x04911ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
the function levelTimerCallback has an argument so the selector must have a colon at the end
selector: "levelTimerCallback:"
the Selector initializer is not needed
i work at an RSS-Feed from the tt_news Extension. My Mainproblem is that the XML-File shows the HTML-Structure of my Website, but i don't know why?
Any Ideas?
Thats my Constantscode:
# RSS2
plugin.tt_news {
# SYS-Folder mit News
pid_list = 61
# Seite mit Singleanzeige
singlePid = 62
displayXML {
xmlTitle = {$c_rss.title}
xmlLink = {$baseURL}
xmlFormat = rss2
rss2_tmplFile = fileadmin/Resources/Private/Templates/rss_2.tmpl
# Anzahl News in Reader
xmlLimit = 10
xmlDesc = {$c_rss.description}
# Sprache
xmlLang = {$c_rss.lang}
title_stdWrap.htmlSpecialChars = 1
title_stdWrap.htmlSpecialChars.preserveEntities = 1
subheader_stdWrap.stripHtml = 1
subheader_stdWrap.htmlSpecialChars = 1
subheader_stdWrap.htmlSpecialChars.preserveEntities = 1
subheader_stdWrap.crop = 425 | ...
subheader_stdWrap.ifEmpty.field = bodytext
xmlLastBuildDate = 1
xmlIcon = main/typo3conf/ext/tt_news/ext_icon.gif
}
}
And thats the TS-Code:
# RSS
page.headerData.1100 = TEXT
page.headerData.1100.value = <link rel="alternate" type="application/rss+xml" title="RSS-Feed" href="{$baseURL}/rss.xml" />
xmlnews = PAGE
xmlnews {
typeNum = 100
10 >
10 < plugin.tt_news
10.pid_list >
10.pid_list = 61
10.singlePid = 63
10.defaultCode = XML
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:text/xml
no_cache = 1
xhtml_cleaning = 0
}
}
TRy with this constans:
### News settings ###
plugin.tt_news {
displayXML {
xmlCaching = 1
xmlLimit = 15
xmlFormat = rss2
xmlTitle = News
xmlLink = http://your.url/
xmlDesc = description
xmlLang = de
title_stdWrap.htmlSpecialChars = 1
title_stdWrap.htmlSpecialChars.preserveEntities = 1
subheader_stdWrap.stripHtml = 1
subheader_stdWrap.htmlSpecialChars = 1
subheader_stdWrap.htmlSpecialChars.preserveEntities = 1
subheader_stdWrap.crop = 425 | ... | 1
subheader_stdWrap.ifEmpty.field = bodytext
xmlLastBuildDate = 1
rss2_tmplFile = fileadmin/Resources/Private/Templates/rss_2.tmpl
}
}
I'm using cocoa JSON framework http://code.google.com/p/json-framework/
Here is the result of an JSON output that I get. I can see that results in dictionary
Response {
"completed_in" = 0.02461;
"max_id" = 10088639298;
"next_page" = "?page=2&max_id=10088639298&q=apple";
page = 1;
query = apple;
"refresh_url" = "?since_id=10088639298&q=apple";
results = (
{
"created_at" = "Sat, 06 Mar 2010 20:35:09 +0000";
"from_user" = leduxcwb;
"from_user_id" = 69744637;
geo = <null>;
id = 10088639298;
"iso_language_code" = pt;
"profile_image_url" = "http://a3.twimg.com/profile_images/459490475/Backup_of_Ledux_LOGO_FUNDO_2_normal.jpg";
source = "<a href="http://echofon.com/" rel="nofollow">Echofon</a>";
text = "FOTOS NOVAS - B-DAY Apple Carraro #applecarraro com #smccarraro #letsdoitbetter Bogus e muito mais - LEDUXcwb - http://bit.ly/9W2GOn";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:09 +0000";
"from_user" = BIEBERBAABY;
"from_user_id" = 87598715;
geo = <null>;
id = 10088639165;
"profile_image_url" = "http://a3.twimg.com/profile_images/736057781/lmaaao__angell_muucch_normal.jpg";
source = "<a href="http://twitter.com/">web</a>";
text = "RT #justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:08 +0000";
"from_user" = TheFerstFamily;
"from_user_id" = 5186275;
geo = <null>;
id = 10088638658;
"iso_language_code" = en;
"profile_image_url" = "http://a1.twimg.com/profile_images/80538644/Sherri_and_Tom_normal.jpg";
source = "<a href="http://apiwiki.twitter.com/" rel="nofollow">API</a>";
text = "Apple & Honeysuckle Refreshing Body Spray 30% off and free shipping http://tinyurl.com/yapqsqf at Bonanzle.";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:07 +0000";
"from_user" = nappypoet;
"from_user_id" = 3727061;
geo = <null>;
id = 10088638027;
"iso_language_code" = en;
"profile_image_url" = "http://a3.twimg.com/profile_images/603999315/DSCN1910_normal.JPG";
source = "<a href="http://m.twitter.com/" rel="nofollow">mobile web</a>";
text = "APPLE STORE!!!!!!!!!!!!";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:06 +0000";
"from_user" = morningnew;
"from_user_id" = 90568021;
geo = <null>;
id = 10088637474;
"iso_language_code" = en;
"profile_image_url" = "http://a1.twimg.com/profile_images/632625890/11238_1187063001649_1380523419_30571850_5695474_n_normal.jpg";
source = "<a href="http://apiwiki.twitter.com/" rel="nofollow">API</a>";
text = "latest video clip Chile, test and keep brand new APPLE iPad here http://bit.ly/ctyW2C [CA people Only]";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:05 +0000";
"from_user" = "MaddieT_Love";
"from_user_id" = 36657123;
geo = <null>;
id = 10088637057;
"iso_language_code" = en;
"profile_image_url" = "http://a3.twimg.com/profile_images/672448029/zzz____normal.jpg";
source = "<a href="http://www.myspace.com/sync" rel="nofollow">MySpace</a>";
text = "TELLiNG OFF KiERSTEN!!!! haha "if yu painted her red,, she'd be a GIANT apple!!!!" (:";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:04 +0000";
"from_user" = TechPsychic;
"from_user_id" = 65162673;
geo = <null>;
id = 10088636187;
"iso_language_code" = en;
"profile_image_url" = "http://a1.twimg.com/profile_images/449688160/dragon_normal.jpg";
source = "<a href="http://apiwiki.twitter.com/" rel="nofollow">API</a>";
text = "Apple announced a beta Launch a status online is trying to which has.";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:03 +0000";
"from_user" = sallyroyerderr;
"from_user_id" = 15188311;
geo = <null>;
id = 10088635728;
"iso_language_code" = en;
"profile_image_url" = "http://a3.twimg.com/profile_images/616259477/IMG_2013_normal.jpg";
source = "<a href="http://twitter.com/">web</a>";
text = "Apple cake and coffee...delicious!";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:35:02 +0000";
"from_user" = "steve_widen";
"from_user_id" = 93551780;
geo = <null>;
id = 10088634985;
"iso_language_code" = en;
"profile_image_url" = "http://a1.twimg.com/profile_images/664143910/stevetweet_normal.jpg";
source = "<a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>";
text = "Apple's Academy Award For Product Placement | http://ow.ly/1f3dD";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:58 +0000";
"from_user" = LessiaFetsch;
"from_user_id" = 100092422;
geo = <null>;
id = 10088633257;
"iso_language_code" = ru;
"profile_image_url" = "http://a3.twimg.com/profile_images/669973111/4_normal.jpg";
source = "<a href="http://twitter.com/">web</a>";
text = "\U043f\U043e\U0434\U0430\U0440\U0438\U043b\U0438 apple magic mouse, \U0441\U0438\U0436\U0443 \U043b\U043e\U043c\U0430\U044e \U0433\U043e\U043b\U043e\U0432\U0443,\U043a\U0430\U043a \U0436 \U0435\U0451 \U043d\U0430\U0441\U0442\U0440\U043e\U0438\U0442\U044c :D \U043d\U0443 \U0434\U0430,\U044f \U0447\U0430\U0439\U043d\U0438\U043a \U0438 \U0447\U0442\U043e :D";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:57 +0000";
"from_user" = "I_Dont_Cin";
"from_user_id" = 80004560;
geo = <null>;
id = 10088632392;
"iso_language_code" = en;
"profile_image_url" = "http://a3.twimg.com/profile_images/735462983/I_Dont_Cin_normal.jpg";
source = "<a href="http://echofon.com/" rel="nofollow">Echofon</a>";
text = "RT #girlKell: these sour apple bitter bitches im not fucking with them";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:54 +0000";
"from_user" = maddenkatie;
"from_user_id" = 80572995;
geo = <null>;
id = 10088631073;
"profile_image_url" = "http://a1.twimg.com/profile_images/712744500/19150_1342329082633_1363398519_30948030_6001641_n_normal.jpg";
source = "<a href="http://twitter.com/">web</a>";
text = "RT #justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:54 +0000";
"from_user" = SirKnowsALot;
"from_user_id" = 90229447;
geo = <null>;
id = 10088630768;
"iso_language_code" = en;
"profile_image_url" = "http://s.twimg.com/a/1267816830/images/default_profile_5_normal.png";
source = "<a href="http://apiwiki.twitter.com/" rel="nofollow">API</a>";
text = "http://ow.ly/WEWQ I wrote a tutorial called How to create iPhone ringtones using only iTunes. It's not that hard. #apple #mp3 #aac #free";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:39 +0000";
"from_user" = ronbentata;
"from_user_id" = 51909217;
geo = <null>;
id = 10088623134;
"iso_language_code" = en;
"profile_image_url" = "http://a3.twimg.com/profile_images/544679831/IMG_3998_z_normal.jpg";
source = "<a href="http://www.linkedin.com/" rel="nofollow">LinkedIn</a>";
text = "Apple's stock reaches a new high - almost $220. wish i have a few (a lot actually)";
"to_user_id" = <null>;
},
{
"created_at" = "Sat, 06 Mar 2010 20:34:38 +0000";
"from_user" = MikaylaFenty;
"from_user_id" = 70426321;
geo = <null>;
id = 10088622471;
"profile_image_url" = "http://a3.twimg.com/profile_images/722158465/selena_gomez_normal.jpg";
source = "<a href="http://twitter.com/">web</a>";
text = "RT #justinbieber: BABY - http://itunes.apple.com/us/album/baby-feat-ludacris-single/id350389778";
"to_user_id" = <null>;
}
);
"results_per_page" = 15;
"since_id" = 0;
}
Here is what NSLog says when I do [obj class] on the object.
2010-03-06 15:37:30.730 LuckyNumbers[61219:207] Current Object type: NSCFString object: query
2010-03-06 15:37:30.731 LuckyNumbers[61219:207] Current Object type: NSCFString object: since_id
2010-03-06 15:37:30.732 LuckyNumbers[61219:207] Current Object type: NSCFString object: next_page
2010-03-06 15:37:30.733 LuckyNumbers[61219:207] Current Object type: NSCFString object: completed_in
2010-03-06 15:37:30.734 LuckyNumbers[61219:207] Current Object type: NSCFString object: results
2010-03-06 15:37:30.736 LuckyNumbers[61219:207] Current Object type: NSCFString object: max_id
2010-03-06 15:37:30.737 LuckyNumbers[61219:207] Current Object type: NSCFString object: page
2010-03-06 15:37:30.737 LuckyNumbers[61219:207] Current Object type: NSCFString object: results_per_page
2010-03-06 15:37:30.738 LuckyNumbers[61219:207] Current Object type: NSCFString object: refresh_url
How do I get the full Dictionary of results?
That's not valid JSON syntax; it's vaguely close but it's also very wrong. I'm not exactly sure what you're asking here, however.
Are you doing this?
NSArray *array = /*can has object from JSON kplzthx*/;
for (id obj in array) {
NSLog(#"Current Object type: %#; object: %#", [obj class], obj);
}
The result of the parse is not an array, it's a dictionary, whose keys are #"completed_in", #"max_id", etc. Those keys are what you're getting in this loop: Looping on a dictionary yields its keys (not in any specific order).
Note that telling the compiler that the variable will hold a pointer to an NSArray does not mean it will; if the above resembles your code, then you are putting a pointer to an NSDictionary (which the JSON parser created and returned to you) into that variable. The compiler has no way to predict this; it can do nothing but believe what you tell it.
It's not clear exactly what you want. If you meant to loop on the array of result dictionaries, then ask the dictionary that the JSON parser returned to you for the object for the key #"results"; that object will be the array of dictionaries.
If you meant to simply get the top-level dictionary representing the complete parse of the JSON data: Congratulations; you have it. It's the object the JSON parser returned to you.
Or, in code:
NSDictionary *topLevelDictionary = /*object from JSON parser*/;
NSArray *resultDictionaries = [topLevelDictionary objectForKey:#"results"];