Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-16-2009, 10:29 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Angry Too long a string for JSONValue ?

Hi everyone,


I'm pretty new to iphone sdk, so please excuse me if my question doesn't make sense !

I have an issue with json parsing :
- I established a connection to a remote server to receive a json object, which looks like this :
Code:
{"news1":{"title":"hello", "content":"hello world"}, "news2":{"title":"hi", "content":"hi world"}, .... }
- In the didReceiveData method, I assigned the json string :
Code:
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- then I built my dictionary :
Code:
NSDictionary *results = [jsonString JSONValue];
As long as the "content" string doesn't exceed a certain number of characters, everything works fine.

But if my "content" string becomes very long (which should be the case at the end of my project), the news do not load and the console returns the following error :
Quote:
2009-11-16 16:25:16.778 newsReaderV5[3448:207] -JSONValue failed. Error trace is: (
Error Domain=org.brautaset.JSON.ErrorDomain Code=5 UserInfo=0x3b29380 "Unescaped control character '0x0'",
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x3b29770 "Object value expected for key: content",
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x3b29850 "Object value expected for key: news1"
)
2009-11-16 16:25:16.789 newsReaderV5[3448:207] -JSONValue failed. Error trace is: (
Error Domain=org.brautaset.JSON.ErrorDomain Code=3 UserInfo=0x3b2a3c0 "Unrecognised leading character"
)
Does anyone have an idea about what all this means ? I'm completely stuck here...

Thanks in advance for your help !
ggekko is offline   Reply With Quote
Old 11-16-2009, 01:32 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default

I found a solution !


After a NSLog, I noticed that the parsed json object was not entirely loaded. I don't know why, but it seems that NSString objects have a limited size.
So I managed getting all that data into my NSString string by doing so :

Code:
	if(jsonString == nil)
	{
	jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];

	}
	else {
		NSMutableString *temp_string = [[NSMutableString alloc] initWithString:jsonString];
		
		[jsonString release];
		jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
		[temp_string appendString:jsonString];
	
		[jsonString release];
		jsonString = [[NSMutableString alloc] initWithString: temp_string];
		[temp_string release];

	}

I know the code is not that clear, but I didn't find any other solution yet !


If anyone finds a better way, let me know !
ggekko is offline   Reply With Quote
Old 07-13-2011, 12:40 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 1
Default similar problem

for update

Code:
	int tmpNetStatus = [[SBJsonStreamParser new]parse:data];
		
		switch (tmpNetStatus) {
			case SBJsonStreamParserComplete:

				break;
			case SBJsonStreamParserWaitingForData:
				jsonString = nil;
				jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
				break;
			case SBJsonStreamParserError:
			{
				if (jsonString == nil) {
					return;
				}
				
				NSMutableString *temp_string = [[NSMutableString alloc] initWithString:jsonString];
				jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
				[temp_string appendString:jsonString];
				[jsonString release];
				jsonString = nil;
				
				
				//do what you want to
				}
			}
				break;
			default:
				break;
		}

Last edited by davidPan; 07-13-2011 at 02:39 AM.
davidPan is offline   Reply With Quote
Old 08-26-2011, 04:45 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
Default

Quote:
Originally Posted by davidPan View Post
for update

Code:
	int tmpNetStatus = [[SBJsonStreamParser new]parse:data];
		
		switch (tmpNetStatus) {
			case SBJsonStreamParserComplete:

				break;
			case SBJsonStreamParserWaitingForData:
				jsonString = nil;
				jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
				break;
			case SBJsonStreamParserError:
			{
				if (jsonString == nil) {
					return;
				}
				
				NSMutableString *temp_string = [[NSMutableString alloc] initWithString:jsonString];
				jsonString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
				[temp_string appendString:jsonString];
				[jsonString release];
				jsonString = nil;
				
				
				//do what you want to
				}
			}
				break;
			default:
				break;
		}

potresti postare il codice completo?
lucav is offline   Reply With Quote
Old 08-26-2011, 05:13 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
Default

can you post the complete code?
thank you
lucav is offline   Reply With Quote
Reply

Bookmarks

Tags
character, json, leading, string, unrecognized

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 254
18 members and 236 guests
2WeeksToGo, @sandris, AdamL, ADY, BrianSlick, Dani77, Dattee, GHuebner, headkaze, mer10, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,747
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:53 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0