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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:31:17+00:00 2026-06-10T09:31:17+00:00

I have some String values like this format, [INFO] [Tue Aug 21 14:54:22 2012]

  • 0

I have some String values like this format,

[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [26]  [Hello]  [;]

I want to convert these strings to JSON using NSJSONSerialization.

I am using the following code to convert the strings,

 for (i = 0; i < [logArray count]; i++) 
{
    individualLogInfoArray = [[logArray objectAtIndex:i] componentsSeparatedByString:kDelimitterSpace];
    [dictionaryArray addObject:individualLogInfoArray];

}

finalLogDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:dictionaryArray,@"Log", nil];
    NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalLogDictionary 
                                                   options:NSJSONWritingPrettyPrinted
                                                     error:&error];

NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JsonString = %@",jsonString);

Then I getting output like this ,

JsonString = {
  "Log" : [
    "[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [26]  [Hello]  [;]",
    "[DEBUG]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [27]  [hi]  [;]",
    "[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [28]  [Its  there]  [;]",
    "[PROD]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [29]  [Welcome]  [;]"
  ]
}

but i want output like this,

{
"log": "[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [26]  [Hello],[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [26]  [Hello],[INFO]  [Tue Aug 21 14:54:22 2012]  [ViewController]  [26]  [Hello]"

}

I don’t know how to generate a JSON string in the above format, please suggest a solution.

  • 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-10T09:31:19+00:00Added an answer on June 10, 2026 at 9:31 am

    The string you’re getting is valid JSON, whereas the string you want is not. So, you won’t be able to use the iOS JSON library to generate invalid JSON.

    You can test validity by using this online utility,

    JSONLint

    Hope that helps.

    UPDATE: Question has since been revised to show valid JSON as required output.

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

Sidebar

Related Questions

I have some double values I want to convert to a string with this
I have some float values I want to convert to a string, I want
I have some string like this: 04:51 05:09 05:29_ 05:49 06:09 06:29 06:49_ 07:09
I have a String with some value. I want to iterate over all classes
HI, I have some string from XML file, and I I want to replace
I have some random string, let's say : s = This string has some
I have a JTable where i enter some values. This is the listener function
I have some data which I am formatting like this: // ... imagine populating
I have string value and Type of some variable (For example int and 32
I have an issue while storing some special character values into db. For e.g.

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.