Click here to Skip to main content
14,545,210 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

I want to convert a Microsoft Dynamics NAV string c# to json.

i have the following string:
private static readonly NavTextConstant text003 = new NavTextConstant(new int[]{1036, 1033}, new string[]{"Vous ne pouvez pas renommer l'enregistrement %1.", "You cannot rename a %1."}, "Table 1192395785", "Table 1192395785 - NamedType 95063322");

I want to get this result:
{
  "NavTextConstant": [
    {
      "Val1": {
         1036,
         1033
      },
      "Val2":{
        "Vous ne pouvez pas renommer l'enregistrement %1.",
        "You cannot rename a %1."
      },
      "Val3" : "Table 1192395785",
      "Val4" : "Table 1192395785 - NamedType 95063322"
   }
}


What I have tried:

I tried to use
Newtonsoft.Json.JsonConvert.SerializeObject
but it seem like it working only if i have a c# class.

In my case i'm getting this string from a file and I don't have a class c# declared for this type.
Posted
Updated 23-May-20 6:33am
v2
Comments
0x01AA 23-May-20 13:30pm
   
And why you expect that something like "Val1", "Val2" etc. can be produced?
I think you need to go with dynamic objects.
Wakachi23 23-May-20 13:58pm
   
I just need the value (1033,1036 etc.) no need really to have a json object or the val1 etc.
I already try Dynamic object. but don't how to fill constructeur with my string.
I'm fetching this string from a file that contains more than 6000 lines.

I try with regular expression but sometimes values contains symbol ({,",}) so it fail.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Maybe you can use DataContractJsonSerializer, see example here: Working with JSON objects in Dynamics CRM Plugins | Microsoft Dynamics 365 CRM Tips and Tricks[^]
   
Comments
Wakachi23 23-May-20 13:06pm
   
Thanks for your response,
I have already checked it, but it's not solving my issue because in my case I have a C# string ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100