本文介绍了如何编写JSONP文件c#.net(桌面应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的工作代码为桌面应用程序创建JSON文件: -



  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 (例外情况)
{

}
}





现在我可以创建JSONP文件。



Do你知道任何解决方案吗?



我尝试过:



私人void GenerateJSONFile(List< works> WorkList)

{

string jsonString =;

JsonSerializerSettings J = new JsonSerializerSettings();

J.NullValueHandling = NullValueHandling.Ignore;

J.DefaultValueHandling = DefaultValueHandling.Ignore;

J.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

尝试

{

jsonString = JsonConvert.SerializeObject(WorkList,Newtonsoft.Json.Formatting.Indented,J);

if (!string.I sNullOrEmpty(jsonString))

{

Common.WriteFile(jsonString,Settings.Default.JSONFilePath,Settings.Default.JSONFilename);

}

}

catch(例外情况)

{



}

}

解决方案

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

}
}

解决方案


这篇关于如何编写JSONP文件c#.net(桌面应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 12:09