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 8413257
In Process

The Archive Base Latest Questions

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

i am succesfully getting data from my server. and after getting it i send

  • 0

i am succesfully getting data from my server. and after getting it i send the data to the function to parse;

- (void)readIn:(NSMutableData *)s {
    NSLog(@"Reading in the following:");
    NSString * prints = [[NSString alloc] initWithData:s  encoding:NSUTF8StringEncoding];
    NSLog(@"%@", prints);

    NSError *error = nil;
    NSData *jsonData = [[NSData alloc] initWithData:s];

    if (jsonData) {

        id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];

        if ([jsonObjects isKindOfClass: [NSArray class]])
            NSLog(@"yes we got an Array");
        else if ([jsonObjects isKindOfClass: [NSDictionary class]])
             NSLog(@"yes we got an dictionary");
        else
              NSLog(@"neither array nor dictionary!");



        if (error) {
            NSLog(@"error is %@", [error localizedDescription]);
            return;
        }

        NSArray *keys = [jsonObjects allKeys];
        for (NSString *key in keys) {
            NSLog(@"%@ is %@",key, [jsonObjects objectForKey:key]);
        }

    } else {

        // Handle Error
    } 
    }

now my print on console is:

    2012-08-17 13:59:57.667 TaraftarlikOyunu[1157:c07] Reading in the following:
2012-08-17 13:59:57.667 TaraftarlikOyunu[1157:c07] {"uID":"5878341","tm":"fb","hh":122,"pt":75,"coin":500,"ll":1,"qlevel":1,"coect":true,"potWeekly":{"pts":75,"intval":604800000},"acent":{"chamunt":0},"mes":[]}
2012-08-17 13:59:57.668 TaraftarlikOyunu[1157:c07] neither array nor dictionary!
2012-08-17 13:59:57.670 TaraftarlikOyunu[1157:c07] error is The operation couldn’t be completed. (Cocoa error 3840.)

it seems legal json object to me. where am i doing wrong?

i am getting data from the server with nsstream; and here is my code to get data:

case NSStreamEventHasBytesAvailable: {
            if(stream == inputStream) {
                NSLog(@"inputStream is ready.");

                uint8_t buf[1024];
                unsigned int len = 0;

                len = [inputStream read:buf maxLength:1024];
            NSLog(@"length %i", len);
                if(len > 0) {

                    NSMutableData* data=[[NSMutableData alloc] initWithLength:0];
                    [data appendBytes: (const void *)buf length:len];
                    [self readIn:data];

                }
            }
            break;
        }
  • 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-10T00:52:57+00:00Added an answer on June 10, 2026 at 12:52 am

    problem is that, json string i get is coming with null termination at the end and when i try to deserialize it it can not be converted to NSDictionary or NSArray. making a little change on the code makes everything perfect. the true code should be like that

    case NSStreamEventHasBytesAvailable: {
            if(stream == inputStream) {
    
                NSLog(@"inputStream is ready.");
    
                uint8_t buf[1024];
                unsigned int len = 0;
    
                len = [inputStream read:buf maxLength:1024];
                NSLog(@"length %i", len);
                if(len > 0) {
    
                    datum =[[NSMutableData alloc] initWithLength:0];
    
                    [datum appendBytes: (const void *)buf length:len-1];
    
    
    
    
                    NSDictionary * jsondict = [NSJSONSerialization JSONObjectWithData:datum options:NSUTF8StringEncoding error:nil];
    
                    NSLog(@"is valid json object %d",[NSJSONSerialization isValidJSONObject:jsondict]);
    
    
                    [self readIn:datum];
                    }
                }
                 else {
                    NSLog(@"no buffer!");
                }
                break;
                }
    
    
        default: {
            NSLog(@"Stream is sending an Event: %i", event);
    
            break;
        }
    }
    

    only difference from the other one is i threw the last byte and it became valid json dictionary.
    thanks for the people who are interested in my question.

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

Sidebar

Related Questions

I am reading data from a TCP/IP stream and am successfully receiving a byte
I want to import data from Excel worksheet into SQL Server database (2008). I
I have an application which needs to load data from a remote server (businesses
I am wondering with this behavior. In my application I am getting data from
Scenario: I am trying for importing data from MS SQL Server to HDFS. But
I have an SSIS package set up to export data from a SQL Server
I'm getting JSON from a server in string format and I am saving it
I am getting some strange behaviour from SQL Server. I have an underlying view
I have an atomfeed with which is succesfully getting parsed. All the articles are
I succesfully used a validator more than once,but after some programming my validators are

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.