Reputation: 564
I have a requirement whereby I need to fetch a set of jsons before making a API call. I am planning to add these json strings in app.config as shown below
<add key="Jsons" value="{""Id"":""25"",""Name"":""Value-1""}"/>
However adding this results in a compilation error "Missing whitespace" at the start of the value. Please let me know if i am missing something. I dont want to create a separate text file to read jsons from. Thats why i decided to use app.config itself
Upvotes: 7
Views: 13226
Reputation: 5632
Your quotes are not correctly formatted. Can you try this:
<add key="Jsons" value='{"Id":"25","Name":"Value-1"}'/>
Upvotes: 13
Reputation: 2982
An app.config
is still XML! You need to use the XML escape sequence for quotes.
<add key="Jsons" value="{"Id":"25","Name":"Value-1"}"/>
Upvotes: 2
Reputation: 192
I see two choices here:
Use "\" to escape:
<add key="Jsons" value="{\"Id\":\"25\",\"Name\":\"Value-1\"}"/>
Use single quote:
<add key="Jsons" value="{'Id':'25','Name':'Value-1'}"/>
Upvotes: 0