Create a JSON Clear Text String for a set of data.

Posted on 2011-02-18
Last Modified: 2012-05-11

I need to create a JSON Clear Text String from a set of data I have.  I will then encrypt this string & pass it to a 3rd party in a URL.
Can I just create a string formatted to how JSON would be formatted, or do I need to create an actual JSON object  (Note I don;t need the string myself after it is created & encrypted & sent via the url.I Presume I can just construct a string without a need for an actual JSONObject)?

if Creating a string. Is the following a good example of how it should be created/formatted?

String jsonReturn='{email' + ':' + '}';
jsonReturn = jsonReturn + '{user_type' + ':' + ' Sales Rep}';
jsonReturn = jsonReturn + '{first_name' + ':' + ' Jim}';
jsonReturn = jsonReturn + '{zip' + ':' + ' 12456}';
Therefore: email, user_type, first_name and zip are my four names and the values follow (e.g. is a value.

Does the above look like a correct JSON Clear Text String being created?

Thanks in advance.
Question by:speedygonzalez
  • 2
  • 2

Author Comment

ID: 34925305
Is the following then a correctly formatted JSON string

{}{user_type: Sales Rep}{first_name: Jim}{zip: 12456}


Author Comment

ID: 34925418
or is the following correct

{,user_type:Sales Rep,first_name: Jim,zip:12456}

LVL 92

Expert Comment

ID: 34929704
yes you can just build the string if thats your preference

> {,user_type:Sales Rep,first_name: Jim,zip:12456}

that last one is correct
LVL 92

Accepted Solution

objects earned 500 total points
ID: 34929716
actually you need to quote strings

{emailjim: '',user_type:'Sales Rep',first_name: 'Jim',zip:'12456'}

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video teaches viewers about errors in exception handling.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question