Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Any JSON serializer/deserializer?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Any JSON serializer/deserializer?

    Hello
    It seems like NT uses pretty chopped version of .net - I didn't manage to find any libs which supports json serialization/deserialization.
    In general is there any library in NT which I can use for that? Or I will need to invent the bicycle?

    #2
    OK, everything was simple: I've just added reference to Newtonsoft.Json.dll and got all needed functionality - right click in the Editor, down in the menu "References..." and add needed assembly.

    Comment


      #3
      why don't you use http://www.newtonsoft.com/json/help/html/Samples.htm
      I use it all the time.

      Comment


        #4
        Originally posted by junkone View Post
        why don't you use http://www.newtonsoft.com/json/help/html/Samples.htm
        I use it all the time.
        Already ...

        Comment


          #5
          Hello
          Has anyone have success connecting to Slack webhook URL with ninja 7 which is on DotNet 3.5?
          Ninja 7 does not support HTTPCLient class.
          So i have to use webclient class but it does not connect to Slack Webhook URL. My research showing it could be because it needs TLS1.2 support which is also not available in NInja 7
          Any help is appreciated

          Comment


            #6
            Hello myrx100,

            I did a quick search and it looks like TLS 1.2 was added in .net 4.5, if that is a requirement of the library you are using you would likely need to use NT8. NT7 uses .net 3.5 so that specifically would not be available.

            While searching I came across the following stack overflow post, if your situation allows for it you can try the suggestion to see if that works, if not the next best suggestion I can make would be using nt8.
            I currently have a web application that uses the .NET 3.5 framework and I am wondering if it will be compatible with TLS 1.2. No where in our code are we dictating TLS version. This is a legacy



            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks Jesse
              I was able to write the code in Ninja 7 to post to slack using the code snippet you posted
              public const SslProtocols _Tls12 = (SslProtocols)0x00000C00; public const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12; ServicePointManager.SecurityProtocol = Tls12

              Comment


                #8
                None of the existing JSON serialization / deserialized worked for me. Here is the solution that works for me:

                Code:
                using System.Web.Script.Serialization;
                
                public T DeserializeJson<T>(string Json)
                {
                    JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();
                    return JavaScriptSerializer.Deserialize<T>(Json);
                }
                
                public string SerializeJson<T>(T Obj)
                {
                    JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();
                    return JavaScriptSerializer.Serialize(Obj);
                }​
                See official MS docs at https://learn.microsoft.com/en-us/do...ramework-4.8.1
                Last edited by skipper-flatiron-18; 08-30-2023, 08:18 AM.

                Comment


                  #9
                  I use JSON quite a lot make sure it is referenced. Right Click script in editor and add reference Click image for larger version

Name:	JSON referenced.png
Views:	231
Size:	106.1 KB
ID:	1265433

                  Comment


                    #10
                    skipper-flatiron-18 The link you provide for the Microsoft website is, sadly, broken (it has an extra space in the link at "...serializ er..."). Not your fault, I think, as there has been a "long-standing" bug in the Forum software that introduces spaces rather randomly and it has affected links I've posted in the past too. Just one of several long-standing bugs in the software, unfortunately.

                    Thanks.
                    Multi-Dimensional Managed Trading
                    jeronymite
                    NinjaTrader Ecosystem Vendor - Mizpah Software

                    Comment


                      #11
                      ​​​​​​check this one....Serialize and deserialize JSON in C#

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by mmckinnm, Today, 01:34 PM
                      3 responses
                      5 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by f.saeidi, Today, 01:32 PM
                      2 responses
                      4 views
                      0 likes
                      Last Post f.saeidi  
                      Started by alifarahani, 04-19-2024, 09:40 AM
                      9 responses
                      55 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by Conceptzx, 10-11-2022, 06:38 AM
                      3 responses
                      60 views
                      0 likes
                      Last Post NinjaTrader_SeanH  
                      Started by traderqz, Today, 12:06 AM
                      9 responses
                      16 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X