Click here to Skip to main content
15,068,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here working code Create JSON file for Desktop application :-

C#
private void GenerateJSONFile(List<Works> WorkList)
        {
            string jsonString = "";
            JsonSerializerSettings J = new JsonSerializerSettings();
            J.NullValueHandling = NullValueHandling.Ignore;
            J.DefaultValueHandling = DefaultValueHandling.Ignore;
            J.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            try
            {
               jsonString = JsonConvert.SerializeObject(WorkList, Newtonsoft.Json.Formatting.Indented, J);
                if (!string.IsNullOrEmpty(jsonString))
                {
                   Common.WriteFile(jsonString,Settings.Default.JSONFilePath, Settings.Default.JSONFilename);
                }
            }
            catch (Exception ex)
            {

            }
        }


Now I can do create JSONP file.

Do you know any solutions?

What I have tried:

private void GenerateJSONFile(List<works> WorkList)
{
string jsonString = "";
JsonSerializerSettings J = new JsonSerializerSettings();
J.NullValueHandling = NullValueHandling.Ignore;
J.DefaultValueHandling = DefaultValueHandling.Ignore;
J.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
try
{
jsonString = JsonConvert.SerializeObject(WorkList, Newtonsoft.Json.Formatting.Indented, J);
if (!string.IsNullOrEmpty(jsonString))
{
Common.WriteFile(jsonString,Settings.Default.JSONFilePath, Settings.Default.JSONFilename);
}
}
catch (Exception ex)
{

}
}
Posted
Updated 1-Jun-16 21:05pm
v2
Comments
VR Karthikeyan 2-Jun-16 2:55am
   
Whats your problem?
.net developer123456789 2-Jun-16 2:57am
   
How to write to a JSONP file using C#? (Desktop Application)
Zafar Sultan 2-Jun-16 3:17am
   
There is nothing like "JSONP" file. JSONP is a technique explained here. What you are trying is probably writing JSON response/output to a file.

1 solution

These are very good links to know about how to write json to a file, try them.
1. Write JSON to a file[^]
2. How to write a Json file in C#? - Stack Overflow[^]
   
Comments
.net developer123456789 2-Jun-16 3:08am
   
Thanks..but How to write to a JSONP(JavaScript Object Notation with Padding) file using C#? (Desktop Application)
Dmitriy Gakh 2-Jun-16 3:26am
   
JSONP is a technique, not a file format. You need to understand JavaScript to have clue how JSONP works.

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