Re: stringWithContentsOfURL bug?
Re: stringWithContentsOfURL bug?
- Subject: Re: stringWithContentsOfURL bug?
- From: Benjámin Salánki <email@hidden>
- Date: Thu, 6 Jan 2005 20:35:11 +0100
Hi,
basically I'll need to create an NSMutableDictionary from the data on the webpage, so I wanted to use something like this:
[NSMutableDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.beszeljukmac.com/faq/update_client.php?action=updateClient&version=%d", [[prefs objectForKey:@"DB Version"] intValue]]]]
where prefs is [NSUserDefaults standardUserDefaults].
the PHP code should display:
<dict><key>Category</key><array><dict><key>category_id</key><string>1</string><key>category_name</key><string>Finder</string></dict><dict><key>category_id</key><string>2</string><key>category_name</key><string>Mail</string></dict><dict><key>category_id</key><string>3</string><key>category_name</key><string>Safari</string></dict></array><key>Entry</key><array><dict><key>entry_id</key><string>1</string><key>category_type</key><string>1</string><key>entry_name</key><string>Ikon másolása</string><key>entry_content</key><string>Másoljunk bármilyen képet vagy ikont (command-C), majd válasszuk ki a Finder-ben azt a programot, állományt vagy mappát amelyikre rá akarjuk illeszteni a másolt képet. A File menü Get Info parancsával (command-I) jelenítsük meg az információs panelt. Itt kattintsunk bele egyszer az ikonba, majd illesszük be a másolt képet vagy ikont (command-V). Természetesen hasonló módon másolható le egy adott állomány ikonja is.</string></dict><dict><key>entry_id</key><string>2</string><key>category_type</key><string>2</string><key>entry_name</key><string>Mail szöveg 1</string><key>entry_content</key><string>Bla bla bla bla bla.
Bla bla.
Bla bla bla.</string></dict><dict><key>entry_id</key><string>3</string><key>category_type</key><string>2</string><key>entry_name</key><string>Mail szöveg 2</string><key>entry_content</key><string>Bla bla bla bla bla.
Bla bla.
Bla bla bla.
Bla bla bla bla bla.</string></dict><dict><key>entry_id</key><string>4</string><key>category_type</key><string>3</string><key>entry_name</key><string>Safari tipp 1</string><key>entry_content</key><string>Bla bla bla bla bla.
Bla bla.
Bla bla bla.
Safari bla.</string></dict></array><key>Comment</key><array><dict><key>comment_id</key><string>1</string><key>entry_type</key><string>2</string><key>comment_text</key><string>Ez egy tök jó tipp :D
õõõûûû</string></dict><dict><key>comment_id</key><string>2</string><key>entry_type</key><string>4</string><key>comment_text</key><string>A Safari állat kis böngészõ.</string></dict></array></dict>
But this gets lost somewhere. I even used utf8encode() to encode the resulting string in UTF-8 and added UTF-8 encoding to the header, but I can't seem to get valid data into my dictionary, so that's when I thought lets load the data into a string, like this:
NSLog(@"%@", [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.beszeljukmac.com/faq/update_client.php?action=updateClient&version=%d", [[prefs objectForKey:@"DB Version"] intValue]]]]);
This produced that strange accented a character as a result.
I tried downloading the URL's contents as NSData, then convert it to an NSString using stringWithUtf8String: by passing it the [NSData bytes] parameter where NSData is the downloaded data, but I get null as a result.
So I'm pretty much stuck here.
ben
stupidFish23
http://www.stupidfish23.com
On Jan 6, 2005, at 2:58, Pete Yandell wrote:
So you do something like this:
NSString* myString = [NSString stringWithContentsOfURL:myURL];
Do you check the value of myString to make sure it's not nil?
Assuming that's not the problem, I bet that you're doing;
NSLog (myString);
instead of:
NSLog (@"%@", myString);
Pete Yandell
P.S. You should always include your code when asking a question on the list. It's hard to tell what you might be doing wrong without knowing exactly what you're doing!
On 06/01/2005, at 11:19 AM, Benjámin Salánki wrote:
Hi,
I am not sure if this is a bug, but I'm really getting tired of experimenting here, maybe some of you can point me towards the obvious direction :D
Here's what I'm trying to do:
I have some data on a webserver in MySQL databases, so I wrote a PHP script that loads the relevant data, and creates a long string that formats the data in good old plist format. Then I print this out.
I try to access the string using the stringWithContentsOfURL: method (which I have used in quite some projects already, so I already know this should work). When my string is short, maybe 5 lines when displayed in Safari, the string gets loaded fine.
Like this:
<dict><key>Category</key><array><dict><key>category_id</key><string>1</string><key>category_name</key><string>Finder</string></dict><dict><key>category_id</key><string>2</string><key>category_name</key><string>Mail</string></dict><dict><key>category_id</key><string>3</string><key>category_name</key><string>Safari</string></dict></array></dict>
But when I add a longer string, suddenly I get garbled data, with NSLog() only outputting the
ã
character. The strange thing is, that wether I use NSString's, NSData's or whatever else's methods it won't work on any of them. But Safari displays it right, and if i copy it from safari and save the text in TextEdit and name it something.plist it opens up just well in the Property List Editor.
Any ideas what might be causing this or do you have a better way of getting data from a MySQL table on the web to a local plist file?
thx,
Ben
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden