且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何编写JSONP文件c#.net(桌面应用程序)

更新时间:2023-10-28 13:50:22

这些是非常好的链接,了解如何将json写入文件,试试它们。

1. 将JSON写入文件 [ ^ ]

2. 如何在C#中编写Json文件? - 堆栈溢出 [ ^ ]

Here working code Create JSON file for Desktop application :-

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)
{

}
}

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[^]