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

  • Home
  • SEARCH
  • 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 6984797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:35:45+00:00 2026-05-27T18:35:45+00:00

I want to convert personArray to a JSON string, and send a request to

  • 0

I want to convert personArray to a JSON string, and send a request to the server.

I tried something like the following code:

@interface Person : NSObject {
    NSString *name;
    int registered;
}
+ (NSMutableArray *) select;
NSMutableArray *personArray = [Person select]; 


NSString *json = @"{ \"";//TODO

for (int i =0 ;i < [personArray count]; i++) {
    Person *temp = [Person objectAtIndex:i];

    [json stringByAppendingFormat:[NSString stringWithFormat:@"\"name\": \"%@\"", temp.name]
}
json = [json stringByAppendingFormat:[NSString stringWithFormat:@"} \""]];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[global userID] forKey:@"user_id"];
[request setPostValue:json forKey:@"json_key"];
[request addRequestHeader:@"Content-type" value:@"application/json"]; 

[request startSynchronous];

The server receives the following data:

{ \"\"name\": \"Tom\"}

The server code is this:

$json = $_POST['json_key'];
echo $json;
$json = json_decode($json, true);
echo $json; // prints nothing

Is there any way to remove the slash, or a prettier solution for converting the object to JSON?

  • 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-05-27T18:35:46+00:00Added an answer on May 27, 2026 at 6:35 pm

    To be sure that the JSON representation is being generated properly, use a general purpose JSON generator (such as Stig Brautaset’s JSON Framewark or yajl-objc) rather than ad hoc conversion.

    JSON Framework:

    @interface Person(SBJson)
    -(id)proxyForJson;
    @end
    
    @implementation Person(SBJson)
    -(id)proxyForJson {
    return [NSDictionary dictionaryWithObjectsAndKeys:
        name,@"name",
        [NSNumber numberWithInt:registered],@"registered",
         nil];
    }
    @end
    
    ...
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
        [request setPostValue:[[Person select] JSONRepresentation] forKey:@"json_key"];
    

    yajl-objc:

    @interface Person(YAJL)
    -(id)JSON;
    @end
    
    @implementation Person(YAJL)
    -(id)JSON {
    return [NSDictionary dictionaryWithObjectsAndKeys:
        name,@"name",
        [NSNumber numberWithInt:registered],@"registered",
         nil];
    }
    @end
    
    ...
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
        [request setPostValue:[[Person select] yajl_JSONString] forKey:@"json_key"];
    

    See also:

    • Encoding custom classes using yajl-objc
    • How to generate JSON programatically using JSON framework for iPhone
    • Send NSMutableArray as JSON using JSON-Framework
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert a primitive to a string, and I tried: myInt.toString(); This
I want to convert ArrayList of Character to String. I read similar thread like
I want to convert (USERID=XYZ USERPWD=123) to USERID=XYZ&USERPWD=123 . I tried (apply #'concatenate 'string
I want to convert the following json and put the values into a data
I want to convert a string to datatime. Here is my code: DateTime? dt
Want to convert some C# code for RX to F# code. The following C#
I want to convert a string into a double and after doing some math
I want to convert a std::string to lowercase. I am aware of the function
I want to convert a string into a series of Keycodes, so that I
I want to convert a list object into a string and insert this string

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.