Click here to Skip to main content
15,885,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have below data in json file

{ "HEADER": { "APPLICATION-ID": "82274992", "CUST-ID": "82274992", "REQUEST-TYPE": "REQUEST", "REQUEST-TIME": "29042013 11:30:00" }, "REQUEST": { "01": "LOW_PRIORITY", "02": "CIR", "03": "HOUSING LOAN", "04": "1000000", "05": "Individual", "06": "softcell@poc.com", "07": "DIRECT", "08": "0.0", "09": "TEST_BANK", "10": "001", "11": "QA/UAT", "12": "HOUSING LOAN", "13": "TESTING_001", "14": "TEST_BRANCH", "15": "PRE SCREEN",
"16": "false", "18": "false", "19": "Individual", "20": "constitution", "21": { "01": "TEST TEST TEST", "02": "TEST" }, "22": "FEMALE", "23": "MARRIED", "27": "26051982", "28": "2", "29": [ { "01": "RESIDENCE", "02": "Owned", "03": "RAUNAK RESIDENCY", "04": "A WING FLAT NO 24 4TH FLOOR , OPP MAAL DHAKKA RD CHINCHWAD", "06": "27", "05": "411019" } ], "30": { "01": "AAAPA0000D" }, "31": [ { "01": "Mobile Phone", "02": "9898989898" }, { "01": "Office Phone", "02": "303030303" } ], "40": "77", "51": "500000", "52": "500000", "54": "500000", "55": "500000" } }

i am getting error "Specified value has invalid CRLF characters."

What I have tried:

string json;

        using (StreamReader r = new StreamReader(Server.MapPath("/json_Docs/Request_Json.json")))
        {
           json = r.ReadToEnd();

        }
Posted
Updated 28-Dec-17 6:37am
Comments
[no name] 28-Dec-17 6:50am    
Your posted json- text seems to be valid according to JSONLint - The JSON Validator[^].
But of course posted text can be different compared to your real data.
Vikram Singh Rathaur 28-Dec-17 6:59am    
its real data which i am using.
Patrice T 28-Dec-17 7:16am    
This site textbox have changed your json.
What we see is not your real data.
Vikram Singh Rathaur 28-Dec-17 7:44am    
{ "HEADER": {
"APPLICATION-ID": "82274992",
"CUST-ID": "82274992",
"REQUEST-TYPE": "REQUEST",
"REQUEST-TIME": "29042013 11:30:00"
},
"REQUEST": {
"01": "LOW_PRIORITY",
"02": "CIR",
"03": "HOUSING LOAN",
"04": "1000000",
"05": "Individual",
"06": "softcell@poc.com",
"07": "DIRECT",
"08": "0.0",
"09": "TEST_BANK",
"10": "001",
"11": "QA/UAT",
"12": "HOUSING LOAN",
"13": "TESTING_001",
"14": "TEST_BRANCH",
"15": "PRE SCREEN",
"16": "false",
"18": "false",
"19": "Individual",
"20": "constitution",
"21": {
"01": "TEST TEST TEST",
"02": "TEST"
},
"22": "FEMALE",
"23": "MARRIED",
"27": "26051982",
"28": "2",
"29": [
{
"01": "RESIDENCE",
"02": "Owned",
"03": "RAUNAK RESIDENCY",
"04": "A WING FLAT NO 24 4TH FLOOR , OPP MAAL DHAKKA RD CHINCHWAD",
"06": "27",
"05": "411019"
}
],
"30": {
"01": "AAAPA0000D"
},
"31": [
{
"01": "Mobile Phone",
"02": "9898989898"
},
{
"01": "Office Phone",
"02": "303030303"
}
],
"40": "77",
"51": "500000",
"52": "500000",
"54": "500000",
"55": "500000"
}
}
[no name] 28-Dec-17 8:32am    
Please read this:
Different Results

If you use a Windows computer you may end up with different results. This is possibly due to the way Windows handles newlines. Essentially, if you have just newline characters (\n) in your JSON and paste it into JSONLint from a Windows computer, it may validate it as valid erroneously since Windows may need a carriage return (\r) as well to detect newlines properly. As a solution, either use direct URL input, or make sure your content's newlines match the architecture your system expects!

while check your data on JSONLint - The JSON Validator[^]

1 solution

Add the following Newtonsoft.Json references
using Newtonsoft.Json.Linq;
using System.IO;
using Newtonsoft.Json;

and try the below code
JObject o1 = JObject.Parse(File.ReadAllText(@"c:/Data/json_Docs/Request_Json.json"));

            string json = string.Empty;
            using (StreamReader file 
                     =File.OpenText(@"c:/Data/json_Docs/Request_Json.json"))
            using (JsonTextReader reader = new JsonTextReader(file))
            {
                JObject o2 = (JObject)JToken.ReadFrom(reader);

                json= o2.ToString();
            }
 
Share this answer
 
Comments
Vikram Singh Rathaur 29-Dec-17 0:11am    
Try but getting same error
Vikram Singh Rathaur 29-Dec-17 0:12am    
getting below error

An exception of type 'System.ArgumentException' occurred in System.dll but was not handled in user code

Additional information: Specified value has invalid CRLF characters.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900