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

The Archive Base Latest Questions

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

I created a servlet which responds to get requests with a byte array created

  • 0

I created a servlet which responds to get requests with a byte array created from json data. I am trying to consume this data in iOS and use NSJSONSerialization to parse it into a NSDictionary, but it fails with the following error

Error Domain=NSCocoaErrorDomain Code=3840 “The operation couldn’t be completed. (Cocoa error 3840.)” (Duplicate key for object around character 11.) UserInfo=0x6833200 {NSDebugDescription=Duplicate key for object around character 11.}

Here is my code:

NSString *query = @"http://localhost:8888/url?method=retrieve";

NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:query]];
NSError *error = nil;
NSString *stringData = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"substring to index 255: %@",  [stringData substringToIndex:255]);
NSDictionary *results = jsonData ? [NSJSONSerialization JSONObjectWithData:[stringData dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error] : nil;
NSLog(@"Response as Dictionary:\n%@", results.description);
if (error) {
    NSLog(@"Error: %@", error);
}

the value of stringData is

{“APPEALS”:{“APPEAL”:{“AppealID”:387423483,”LastEdit”:”1 . . .

Response as Dictionary returns (null) obviously since there is an error
I am guessing that it has something to do with the fact that my server sends the data in an output stream as a byte[] (java) and it is not formatted correctly as json when received in iOS, but it doesn’t make sense to me why it would fail at character 11 “:”
FYI, the server is written on Google App Engine in java and the localhost url is the local dev server. The json data was created using Jackson Generator library. Thanks!

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

    I discovered the answer myself: when the error points to a duplicate key at a “:” character, that means that some key within the following json array is duplicated, not necessarily the one immediately following that character index. From my json data above, I had many “APPEAL” entries, that when turned into an NSDictionary will throw an error since there can be only 1 value for a given key. I believe my confusion arose from reading a Jackson json generator tutorial which described creating entries with the same key so that they can later be serialized into many instances of an object with “key” as the object class name (so I could have created many APPEAL objects using a Jackson parser, but not so in NSJSONSerialization).

    I also had concatenated several json files server side:

    ( {“table”:{“title”:value}}{“anotherTable”:{“title”:value}} )

    so that my url request response could serve several files with 1 request (cost efficiency), but these had to be split client side and serialized individually since “}}{” isn’t legal json format.

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

Sidebar

Related Questions

I've created a servlet which reads the content of a file to a byte
I've created a servlet which returns a stream (from an MP3 file) beginning at
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I have a web application code which uses jsp, servlet and ejb. I created
I ve created a sample REST web service which writes some data in a
I am creating a table based on result from servlet, which contains a checkbox
I have a Java (6) application which uses Hibernate (V3.3.2) to read data from
I have the following problem: I created the servlet which should draw a dynamic
In a servlet program I created a DAO class containing a function ,which I
I want to add logging to my Servlet, so I've created Filter which should

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.