I have to premise that I a SQL guy and not a C# guy.
I have to ingest such a JSon:
[
{
"gameId": "a_string_id",
"name": "A string with the name",
"width": 1280,
"height": 720,
"description": "A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble A lot of mumble jumble",
"themeUrl": "/address1/address2/address3/filename.jpg",
"thumbnailUrl": "/address1/address2/address3/filename.jpg",
"verticalThumbnailUrl": "",
"helpUrl": "",
"trivia": [],
"traits": [
"aString"
],
"seoName": "a-long-name",
"friendlyName": "a-friendly-name"
},
{
"gameId": "a_string_id",
"name": "A string with the name",
"width": 1600,
"height": 878,
"description": "",
"themeUrl": "/address1/address2/address3/filename.jpg",
"thumbnailUrl": "/address1/address2/address3/filename.jpg",
"verticalThumbnailUrl": "",
"helpUrl": "",
"trivia": [],
"traits": [],
"seoName": "a-long-name",
"friendlyName": "a-friendly-name"
}
]
I need to do this with a script task source. I need to put one entity of the json in every row, preferably already separated into columns, because the total json is very long and there is no such variable that can contain it
My code is the following:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Collections.Generic;
using System.Net;
using System.Web.Script.Serialization;
using System.Collections;
/// <summary>
/// This is the class to which to add your code. Do not change the name, attributes, or parent
/// of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
/// <summary>
/// This method is called once, before rows begin to be processed in the data flow.
///
/// You can remove this method if you don't need to do anything here.
/// </summary>
public override void PreExecute()
{
base.PreExecute();
}
/// <summary>
/// This method is called after all the rows have passed through this component.
///
/// You can delete this method if you don't need to do anything here.
/// </summary>
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
/*
Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
*/
String json = DownloadJson("http://someapi.com");
// Convert json string to .net object using the old school JavaScriptSerializer class
//JavaScriptSerializer serialize = new JavaScriptSerializer();
//Root righe = (Root)serialize.Deserialize(json, typeof(Root));
// Loop through array of earthquakes, outputing desired values to SSIS buffer
//foreach (var feature in righe.MyArray)
//{
// Output0Buffer.AddRow();
// Output0Buffer.gameid = feature.gameid;
//}
Output0Buffer.AddRow();
Output0Buffer.gameid = json;
}
public static string DownloadJson(string downloadURL)
{
using (WebClient client = new WebClient())
{
return client.DownloadString(downloadURL);
}
}
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class MyArray
{
public string gameId { get; set; }
public string name { get; set; }
public int width { get; set; }
public int height { get; set; }
public string description { get; set; }
public string themeUrl { get; set; }
public string thumbnailUrl { get; set; }
public string verticalThumbnailUrl { get; set; }
public string helpUrl { get; set; }
public List<string> trivia { get; set; }
public List<object> traits { get; set; }
public string seoName { get; set; }
public string friendlyName { get; set; }
internal static IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
public string gameid { get; set; }
}
public class Root
{
public List<MyArray> MyArray { get; set; }
}
public class MyArrayList : IEnumerable<MyArray>
{
private List<MyArray> carbootsales;
public IEnumerator<MyArray> GetEnumerator()
{
return carbootsales.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return MyArray.GetEnumerator();
}
}
}
For now I am just trying to work with 1 column, GameId.
The error that I receive is the following:
at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.SetString(Int32 columnIndex, String value) at Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer.set_Item(Int32 columnIndex, Object value) at ScriptMain.CreateNewOutputRows() at UserComponent.PrimeOutput(Int32 Outputs, Int32[] OutputIDs, PipelineBuffer[] Buffers, OutputNameMap OutputMap) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PrimeOutput(Int32 outputs, Int32[] outputIDs, PipelineBuffer[] buffers)
This error is arabic for me.
If someone colud help, even proposing a new approach to the problem, it would be great.
Thanks


MyArray,RootandMyArrayListfor? It looks like you don't use them at all and just setOutput0Buffer.gameid = json;. Does your problem reproduce with justOutput0Buffer.gameid = json;?