AO bit coming in NSArray not NSDictionary

Post here all your questions related with the SmartFoxServer iPhone API

Moderators: Lapo, Bax

Post Reply
ZIGraham
Posts: 10
Joined: 01 Mar 2010, 17:39

AO bit coming in NSArray not NSDictionary

Post by ZIGraham »

Since I use a string as the key to load m_Scores in my Java extension here:

Code: Select all

				int tScore = (int)m_Scores.getNumber( u.getName() );
				m_Scores.putNumber( u.getName(), tScore + 1 );
				m_ReadyPlayers.clear();
				res.put("message", "answer_correct");
				res.put("winner", u.getName());
				res.put("names", GetReadyString());
				res.put("scores", m_Scores);
I would expect to have "scores" be a Dict on the iPhone. But it comes up an Array, which I can verify by dumping it to a file:

Code: Select all

<dict>
	<key>message</key>
	<string>answer_correct</string>
	<key>names</key>
	<string></string>
	<key>scores</key>
	<array>
		<integer>1</integer>
	</array>
	<key>winner</key>
	<string>Mel</string>
</dict>
Scores comes in as an Array, but I want to key off the player name so I don't have to worry about maintaining parallel arrays.
ZIGraham
Posts: 10
Joined: 01 Mar 2010, 17:39

Post by ZIGraham »

While I am hoping for a quick solution from the Internet (that's you), I'm poking around. First off, I love the INF code. It is beautifully organized. I have debugged some crap in my day, and I picked up how this worked in minutes. Love. It.

Contrarily, the problem lies in the craphole that is CXMLElement. It puts a "a" where it should put an "o".

Code: Select all

			// Create nested array				
			if ([objType isEqualToString:@"a"]) {
				newObj = [NSMutableArray array];
			}
			// Create nested object
			else if ([objType isEqualToString:@"o"]) {
				newObj = [NSMutableDictionary dictionary];
			}
It is INFSmartFoxSerilizer::xml2obj who gets tricked by the bug. He makes a NSArray and then recurses in to fill it out. When he gets to the data, he has the correct stuff: varname = "Mel", varval = 1.

Code: Select all

			if ([*o isKindOfClass:[NSDictionary class]]) {
				[*o setObject:varValue forKey:varName];
			}
			else {
				[*o addObject:varValue];
			}
But then because of the o->a mistake, the name is just forgotten.


I'm going to slog through the very non-beautiful cXML stuff now, but that's where I am now. This seems like an actual real system bug and not just me screwing something up.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply