问题描述:

I've got code like below (it just edit JSON and put new stuff in place pointed by JSONPath):

JToken jp = JToken.Parse(json);

IEnumerable<JToken> nd = jp.SelectTokens(path);

JToken newj = JToken.Parse(newval);

foreach (JToken vl in nd)

((JToken)value).Replace(newj);

json, path, newval are strings. I've got no problem when i'm trying to add new int, float, date, bool, null etc... Problem is when i'm trying to add string. Format with quotes is correct ("newstring"), but I need to add string without quotes as well, but i've got an exception ("Unexpected end when reading JSON. Path ''[...]).

Is there any option to parse string without quotes?

网友答案:

A string in JSON is defined as

A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).

If your input contains non-numeric characters that aren't surrounded by quotes, you have an invalid JSON string.

BTW, JSON doesn't define dates either. The ISO 8601 format is used by convention.

相关阅读:
Top