-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSerializeToJson.cs
More file actions
40 lines (36 loc) · 1.33 KB
/
Copy pathSerializeToJson.cs
File metadata and controls
40 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using EdiFabric.Core.Model.Edi;
using EdiFabric.Examples.NCPDP.Script.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.Script106;
namespace EdiFabric.Examples.NCPDP.Script.JSON
{
class SerializeToJson
{
/// <summary>
/// Serialize an NCPDP object to Json using Json.NET
/// </summary>
public static void Run()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
var ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + Config.TestFilesPath + @"\PrescriptionRequest_NEWRX.txt");
List<IEdiItem> ncpdpItems;
using (var ncpdpReader = new NcpdpScriptReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
{
ncpdpItems = ncpdpReader.ReadToEnd().ToList();
}
var transactions = ncpdpItems.OfType<TSNEWRX>();
foreach (var transaction in transactions)
{
var json = Newtonsoft.Json.JsonConvert.SerializeObject(transaction);
Debug.WriteLine(json.ToString());
}
}
}
}