Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:52:32+00:00 2026-06-16T00:52:32+00:00

Is there any good tutorial/source code to parse jSon data into the cocos2d project?

  • 0

Is there any good tutorial/source code to parse jSon data into the cocos2d project? I know how to parse jSon (also the XML) into the xcode and display into the tableview but I need to do that for my cocos2d project.
Here is what I was trying to do:

#import "Eighties.h"
#import "HelloWorldLayer.h"
#import "GameScene.h"
#import "JSON.h"
#define kLatestKivaLoansURL @"http://api.kivaws.org/v1/loans/search.json?status=fundraising"
@implementation Eighties
@synthesize responseData;
+(CCScene *) scene
{
  // 'scene' is an autorelease object.
  CCScene *scene = [CCScene node];

  // 'layer' is an autorelease object.
  Eighties *layer = [Eighties node];

  // add layer as a child to scene
  [scene addChild: layer];

  // return the scene
  return scene;
}


-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {

    CGSize winSize = [[CCDirector sharedDirector] winSize];

    CCSprite *bg = [CCSprite spriteWithFile:@"bg.jpg"];
    [bg setPosition:ccp(winSize.width/2, winSize.height/2)];
    [self addChild:bg z:0];

    /*
    CCMenuItem *menuItems = [CCMenuItemImage itemWithNormalImage:@"back_pink.png" selectedImage:@"back_blue.png" block:^(id sender) {
        NSLog(@"Pressed");
        [[SimpleAudioEngine sharedEngine] playEffect:@"tongue-clap.wav"];
        [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[GameScene scene] withColor:ccWHITE]];
    }];
     */


    CCMenuItem *menuItems2 = [CCMenuItemImage itemWithNormalImage:@"back_pink.png" selectedImage:@"back_blue.png" target:self selector:@selector(loadData)];

    menuItems2.position = ccp(winSize.width/2-50, winSize.height/2-50);

    CCMenu *menu = [CCMenu menuWithItems:menuItems2, nil];
    menu.position = ccp(winSize.width/2, winSize.height/2);
    [self addChild:menu];





}
return self;
}

-(void)test {
NSLog(@"Success");
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Success"
                                                  message:@"Test Method Called"
                                                 delegate:nil
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
[message show];
}

-(void)loadData
{
self.responseData = [NSMutableData data];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:kLatestKivaLoansURL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[connection release];
self.responseData = nil;
}

#pragma mark -
#pragma mark Process loan data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;

NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"loans"];
[responseString release];

//choose a random loan
for (int i=0; i<=18; i++) {
    NSDictionary* loan = [latestLoans objectAtIndex:i];

    //fetch the data
    NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];
    NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
    //float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];

    //NSString* name = [loan objectForKey:@"name"];
    //NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];

    //set the text to the label
    /*
    label.text = [NSString stringWithFormat:@"Latest loan: %@ from %@ needs another $%.2f, please help",
                  name,country,outstandingAmount
                  ];
     */

    NSLog(@"%d",i);
    //NSLog(@"%@",label.text);
    NSLog(@"\n");
    /*
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:name
                                                      message:country
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
    [message show];
     */
}

}



@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:52:33+00:00Added an answer on June 16, 2026 at 12:52 am

    There are a lot of ways to deserialize JSON objects, some ways are even baked into the SDK.

    This question details a few ways you can approach the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any good tutorial or code snippet out there on how to use
I want to learn about debian source packaging.Is there any good tutorial for that.Please
Does anyone know any good tutorial about using NAnt for native code build process
Is there any good tutorial for creating WPF controls entirely at runtime? Thanks
Are there any good technical solutions for extremely long term archiving of data, for
Are there any good open source frameworks for developing computer system emulators? I am
Is there any good tutorial and example for restful web services using jquery &
Hi How to create a CountDown Timer? Is there any good tutorial about it?
Is there any good tutorial on how to use ResourceManager in WPF binding ?
Is there any good tutorial from where, I could find, How to develop a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.