using JSON in cocoa - iphone

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"];

Related

Fatal error using AlamoFireImage to load a url of Arrays using the .af_setImage method in a CollectionView

I'm getting an Array of urls from my REST API and I want to use them to load images from the server using AlamofireImage .af_setImage method for my collection view cells. But I'm getting the following error message in the debug console:
fatal error: unexpectedly found nil while unwrapping an Optional value
This is the code I'm using:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionViewCellIdentifiers.searchResultCell, for: indexPath) as! CreaTuCanastaCollectionViewCell
let urlString = productPictures[indexPath.item]
if let url = URL(string: productPictures[indexPath.item]) {
cell.imageView.af_setImage(withURL: url)
}
return cell
}
}
The strange thing is that the debug console throws this:
Which means the values are there, yet it keeps throwing me the
fatal error:
unexpectedly found nil while unwrapping an Optional value
Any ideas?
Edit
I tried using SDImage instead of AlamoFireImage
if let url = URL(string: productPictures[indexPath.item]) {
cell.imageView.sd_setImage(with: url)
}
And I get the same results
Edit
I tried a different approach this time I put this code inside the cellForItemAt method:
Alamofire.request(urlArray).responseImage { response in
debugPrint(response)
print(response.request)
print(response.response)
print(response.result)
if let image = response.result.value {
cell.imageView.image = image
}
Which gives me this response in the debugging console:
SUCCESS
<UIImage: 0x620000283fc0>, {300, 300}
[Response]: <NSHTTPURLResponse: 0x62800002cb80> { URL: https://i1.wp.com/pixan.wpengine.com/wp-content/uploads/2016/07/canasta-pareja.jpg?fit=600%2C600&ssl=1 } { status code: 200, headers {
"Cache-Control" = "public, max-age=63115200";
"Content-Length" = 24757;
"Content-Type" = "image/jpeg";
Date = "Thu, 01 Dec 2016 06:06:41 GMT";
Etag = "\"629f656831de2958\"";
Expires = "Sat, 01 Dec 2018 18:00:39 GMT";
"Last-Modified" = "Thu, 01 Dec 2016 06:00:39 GMT";
Link = "<https://pixan.wpengine.com/wp-content/uploads/2016/07/canasta-pareja.jpg>; rel=\"canonical\"";
Server = nginx;
Vary = Accept;
"x-bytes-saved" = 2467;
"x-content-type-options" = nosniff;
"x-nc" = "HIT bur 66";
} }
[Data]: 24757 bytes
[Result]: SUCCESS: <UIImage: 0x6280002830c0>, {300, 300}
[Timeline]: Timeline: { "Request Start Time": 502265200.175, "Initial Response Time": 502265200.756, "Request Completed Time": 502265200.813, "Serialization Completed Time": 502265200.821, "Latency": 0.581 secs, "Request Duration": 0.638 secs, "Serialization Duration": 0.008 secs, "Total Duration": 0.645 secs }
Optional(https://i1.wp.com/pixan.wpengine.com/wp-content/uploads/2016/07/canasta-pareja.jpg?fit=600%2C600&ssl=1)
Optional(<NSHTTPURLResponse: 0x62800002cb80> { URL: https://i1.wp.com/pixan.wpengine.com/wp-content/uploads/2016/07/canasta-pareja.jpg?fit=600%2C600&ssl=1 } { status code: 200, headers {
"Cache-Control" = "public, max-age=63115200";
"Content-Length" = 24757;
"Content-Type" = "image/jpeg";
Date = "Thu, 01 Dec 2016 06:06:41 GMT";
Etag = "\"629f656831de2958\"";
Expires = "Sat, 01 Dec 2018 18:00:39 GMT";
"Last-Modified" = "Thu, 01 Dec 2016 06:00:39 GMT";
Link = "<https://pixan.wpengine.com/wp-content/uploads/2016/07/canasta-pareja.jpg>; rel=\"canonical\"";
Server = nginx;
Vary = Accept;
"x-bytes-saved" = 2467;
"x-content-type-options" = nosniff;
"x-nc" = "HIT bur 66";
} })
SUCCESS
<UIImage: 0x6280002830c0>, {300, 300}
2016-12-01 00:06:41.110589 pixan[9961:2940658] []
But I'm still getting the same mistake.
var urlstr = ""
if let urlString = productPictures[indexPath.item] as? String
{
urlstr = urlString
}
cell.imageView.sd_setImageWithURL(NSURL(string: urlstr!), placeholderImage: UIImage(named: "imgPlaceHolder"), completed: { (image, error, cacheType, imageURL) -> Void in})

Implementing Paypal IPN with ASP vNext

I'm using IPN Simulator to send the requests:
https://developer.paypal.com/developer/ipnSimulator
When I receive the IPN, I make a POST to paypal with the same data, adding &cmd=_notify-validate at the end. Problem is I always receive "INVALID" response. Is it because of IPN simulator or am I posting a wrong request ?
This is my IPN Controller:
[HttpPost]
public string IPN()
{
bool useSandbox = true;
StringBuilder to_send = new StringBuilder();
foreach (string key in Request.Form.Keys)
{
if (to_send.ToString().Equals(""))
to_send.AppendFormat("{0}={1}", key, Request.Form[key]);
else
to_send.AppendFormat("&{0}={1}", key, Request.Form[key]);
}
string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
: "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
to_send.AppendFormat("&{0}={1}", "cmd", "_notify-validate");
string strRequest = to_send.ToString();
req.ContentLength = strRequest.Length;
string response = "";
using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{
streamOut.Write(strRequest);
streamOut.Close();
using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
{
response = streamIn.ReadToEnd();
}
}
}
Here's what I receive from paypal :
> payment_type: instant
payment_date: Sun Aug 09 2015 12:23:13 GMT+0300 (GTB Daylight Time)
payment_status: Completed
address_status: confirmed
payer_status: verified
first_name: John
last_name: Smith
payer_email: buyer#paypalsandbox.com
payer_id: TESTBUYERID01
address_name: John Smith
address_country: United States
address_country_code: US
address_zip: 95131
address_state: CA
address_city: San Jose
address_street: 123 any street
business: seller#paypalsandbox.com
receiver_email: seller#paypalsandbox.com
receiver_id: seller#paypalsandbox.com
residence_country: US
item_name: something
item_number: AK-1234
quantity: 1
shipping: 3.04
tax: 2.02
mc_currency: USD
mc_fee: 0.44
mc_gross: 12.34
mc_gross1: 12.34
txn_type: web_accept
txn_id: 363750782
notify_version: 2.1
custom: xyz123
invoice: abc1234
test_ipn: 1
verify_sign: AUxvCDK2PEEhNsHhVyUQ8Y-mDqfQARYxDdlEIxTy83GhdfASQp4iG0Rj
And here's what I'm posting back:
payment_type=instant&payment_date=Sun Aug 09 2015 12:23:13 GMT+0300 (GTB Daylight Time)&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer#paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John Smith&address_country=United States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San Jose&address_street=123 any street&business=seller#paypalsandbox.com&receiver_email=seller#paypalsandbox.com&receiver_id=seller#paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross1=12.34&txn_type=web_accept&txn_id=363750782&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AUxvCDK2PEEhNsHhVyUQ8Y-mDqfQARYxDdlEIxTy83GhdfASQp4iG0Rj&cmd=_notify-validate
Edit 1:
I tried changing the encoding to UTF-8 as it says on paypal documentation, but it still doesn't work :
Ensure that you use the same character encoding for your response string as the encoding specified in the charset field of the original IPN message. When testing using the IPN Simulator, the character encoding will always be UTF-8.
byte[] byteArray = Encoding.UTF8.GetBytes(strRequest);
string response = "";
using (BinaryWriter streamOut = new BinaryWriter(req.GetRequestStream(), System.Text.Encoding.UTF8))
{
streamOut.Write(byteArray, 0, byteArray.Length);
streamOut.Close();
using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
{
response = streamIn.ReadToEnd();
}
}
Is it possible that the variables in Request.Form are not in the order they have been sent ?
cmd=_notify-validate is required to be preceding the original variables not succeeding them, you may want make some adjustment in your to_send StringBuilder code block to something like this:
StringBuilder to_send = new StringBuilder();
to_send.Append("cmd=_notify-validate");
foreach (string key in Request.Form.Keys)
{
to_send.AppendFormat("&{0}={1}", key, Request.Form[key]);
}
string strRequest = to_send.ToString();
p.s Refer here for IPN trouble shooting tips , this would be quite helpful as most of the issues have been covered in there

parsing JSON file

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];

Intuit Anywhere : Invalid Signature Error 401

I am tying to fetch Accounts Before a certain date
I use the following code
TimeZoneInfo pst = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
DateTime now = TimeZoneInfo.ConvertTime(new DateTime(2012, 06, 30), pst);
accountQuery.CreateTime = now;
accountQuery.SpecifyOperatorOption(FilterProperty.CreateTime,
FilterOperatorType.BEFORE);
accountQuery.PageNumber = 1;
accountQuery.ResultsPerPage = 100;
string a = Response.ToString();
List<Intuit.Ipp.Data.Qbo.Account> accounts =
accountQuery.ExecuteQuery<Intuit.Ipp.Data.Qbo.Account>(context)
.ToList<Intuit.Ipp.Data.Qbo.Account>();
But I get an error Unauthorized OAuth Token: signature_invalid

progress jumps from 0 to 1 with ASIHTTPRequest, also AccurateProgress

I want to show the Progress from a Download.
I want to load an Document and show it in an Webview.
Everything is working, only my progress(the - (void)setProgress:(float)newProgress method) shows up 4 times and says value: 0.000000.
Even the -(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes method jumps from received bytes 1 then to its original size.
What Iam doing wrong?
The Server sends me an Response Header:
{
"Cache-Control" = "private,max-age=0";
"Content-Length" = 22993;
"Content-Type" = "application/vnd.ms-word.document.12";
Date = "Tue, 28 Feb 2012 12:20:18 GMT";
Etag = "\"{EA1043C4-BE59-4775-AAC0-D25141572D94},2\"";
Expires = "Mon, 13 Feb 2012 12:20:18 GMT";
"Last-Modified" = "Wed, 13 Apr 2011 11:04:06 GMT";
MicrosoftSharePointTeamServices = "14.0.0.4762";
"Persistent-Auth" = true;
"Public-Extension" = "http://schemas.microsoft.com/repl-2";
ResourceTag = "rt:EA1043C4-BE59-4775-AAC0-D25141572D94#00000000002";
SPRequestGuid = "e4791157-4b6f-4961-84e1-2979d23bf5bc";
Server = "Microsoft-IIS/7.5";
"Set-Cookie" = "WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/, WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/, WSS_KeepSessionAuthenticated={d2e7fd96-aad9-429d-b85d-64a13026c693}; path=/";
"X-Content-Type-Options" = nosniff;
"X-Powered-By" = "ASP.NET";
"X-SharePointHealthScore" = 0;
}
ASIHTTPRequest *asiRequestTemp = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: self.documentURL]];
[asiRequestTemp setTimeOutSeconds:10];
[self setAsiRequestDocumentViewer:asiRequestTemp];
[asiRequestDocumentViewer setDelegate:self];
[asiRequestDocumentViewer setUseKeychainPersistence:YES];
[asiRequestDocumentViewer setUseSessionPersistence:YES];
[asiRequestDocumentViewer setShowAccurateProgress:YES];
[asiRequestDocumentViewer setDownloadProgressDelegate:self];
[asiRequestDocumentViewer setDownloadDestinationPath:mediaPath];
[asiRequestDocumentViewer startAsynchronous];
Whats wrong with that, even the Content Length is shown up!
I experienced a similar problem. How large is the data you're downloading? Have you checked how it's coming in? ASIHTTPRequest does't start updating your progress download until it has successfully downloaded your headers, and I've noticed that if the data is small enough to come in in two or three bursts, setProgress will be called only with a value of 0.0 and 1.0.