首页 > 解决方案 > 在 C# 中将字符串转换为 json 格式。Newtonsoft.json 显示黄色标记

问题描述

我是 SSIS 的新手。我正在尝试将字符串转换为 JSON 格式,如图所示。我安装了 Newtonsoft Json。但它显示黄色三角形标记。

我已经安装了 Newtonsoft 的所有版本。但它仍然显示错误,而#

region Namespaces
using Newtonsoft.Json.Linq;
using System;
using System.Windows.Forms;#
endregion

namespace ST_9a0af2e4537b4d26adaef11149343faa {

 public partial class ScriptMain: Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase {



  public void Main() {


   var myJsonString = "{report: {Id: \"aaakkj98898983\"}}";
   MessageBox.Show(myJsonString);

   try {
    // when i add this line to my package then the package is not 
    excuting.if i remove this line then package is excuting.
    JObject.Parse("{report: {\"Id\": \"aaakkj98898983\"}}");
   } catch (Exception e) {
    MessageBox.Show(e.ToString());
   }




   Dts.TaskResult = (int) ScriptResults.Success;
  }

 }
}

脚本任务。我的 IDE 版本是 Visual Studio 2015 Professional。

安装 Newtonsoft 后不显示。当我关闭脚本任务弹出窗口并再次打开脚本任务编辑器时,它显示黄色感叹号,当我选择 Newtonsoft 包并检查属性时,它的路径和版本显示 0.0.0.0。然后我下载了 Newtonsoft 包并引用 newtonsoft.json.dll 文件添加引用。然后它显示路径和版本。

但是当我运行包时它显示错误。

我也尝试按照文章进行操作,但没有成功。

将 JSON 字符串转换为 JSON 对象 c# https://www.c-sharpcorner.com/article/json-serialization-and-deserialization-in-c-sharp/ https://www.newtonsoft.com/json/help/html /M_Newtonsoft_Json_Linq_JObject_Parse.htm https://www.nuget.org/packages/System.Json/ 如何在没有 JSON.NET 库的情况下解析 JSON? 命名空间中不存在 Json 使用 SSIS 中的 C# 脚本解析 JSON 字符串 https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio https ://www.dotnetjalps.com/2014/04/converting-csharp-object-json-string.html 在 .Net 4.0 中找不到 JavaScriptSerializer

https://riptutorial.com/json-net/topic/1861/getting-started-with-json-net http://www.rockprogrammer.com/2017/08/how-to-install-json-.net- in-visual-studio-2015.htmls

有人可以帮我解决这个问题吗?

谢谢希夫罗伊
_

标签: c#.netssismsbi

解决方案


谢谢大家 。

最后,我可以通过流动 Joost van Rossum 文章来解决问题。感谢 Joost van Rossum

将程序集添加到 GAC 在我们可以使用我们的程序集之前,我们必须将它添加到全局程序集缓存 (GAC)。再次打开 Visual Studio 2008 命令提示符(对于 Vista/Windows7/等,以管理员身份打开)。并执行以下命令。gacutil /id:\myMethodsForSSIS\myMethodsForSSIS\bin\Release\myMethodsForSSIS.dll

有关更多信息,请阅读本文 http://microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html https://social.msdn.microsoft.com/Forums/sqlserver/en- US/d70cac36-6aa5-42cb-89a8-1a24cb5a0cad/cant-find-external-dll-reference-in-ssis-2012-script-task?forum=sqlintegrationservices


推荐阅读