• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

asp .net with JSON string

Hi -

I have a string that is stored in the format of JSON
i.e {"comment": "Hello this is a comment"}
I grad the string on the server and send it to jquery to parse.
Everything works great until a someone make a comment like this...
- Hello this is a *comment* - i say "this is fun"
This really messes with my JSON string on the front end

Is there a simple way to encode a JSON string?

Thanks

0
doctor069
Asked:
doctor069
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
You need to escape char like the double quotes : Hello this is a *comment* - i say \"this is fun\"

Check the string section here : http://json.org/
0
 
doctor069Author Commented:
Thanks but I am not using the NetJSON library on asp .net doesn't Microsoft  have a built in encoder?
0
 
leakim971PluritechnicianCommented:
>Thanks but I am not using the NetJSON

why << but >> ?

you need to put a backslash for each reserved character for example with replace : http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx

http://www.apacheserver.net/q25415/Replace-double-quotes-in-json-string-with-empty-string 
0
 
doctor069Author Commented:
Downloaded Newtonsoft.Json.Net20.dll and I am using:

Json.JsonConvert.SerializeObject(mystring)

Everything seems to work unless I have a word like don't or shouldn't

I thought SerializeObject would handle the ' an I missing something?
 
0
 
doctor069Author Commented:
a little short in the solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now