PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, December 17, 2022

[FIXED] How to write JSON string value in code?

 December 17, 2022     c#, json, string, syntax     No comments   

Issue

I want to store the following string in a String variable

{"Id":"123","DateOfRegistration":"2012-10-21T00:00:00+05:30","Status":0}

This is the code I use ..

String str="{"Id":"123","DateOfRegistration":"2012-10-21T00:00:00+05:30","Status":0}";

.. but it's showing error ..


Solution

You have to do this

String str="{\"Id\":\"123\",\"DateOfRegistration\":\"2012-10-21T00:00:00+05:30\",\"Status\":0}";


Please see this for reference
Also from msdn :)

Short Notation  UTF-16 character    Description
\'  \u0027  allow to enter a ' in a character literal, e.g. '\''
\"  \u0022  allow to enter a " in a string literal, e.g. "this is the double quote (\") character"
\\  \u005c  allow to enter a \ character in a character or string literal, e.g. '\\' or "this is the backslash (\\) character"
\0  \u0000  allow to enter the character with code 0
\a  \u0007  alarm (usually the HW beep)
\b  \u0008  back-space
\f  \u000c  form-feed (next page)
\n  \u000a  line-feed (next line)
\r  \u000d  carriage-return (move to the beginning of the line)
\t  \u0009  (horizontal-) tab
\v  \u000b  vertical-tab


Answered By - Freak
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing