Click here to Skip to main content
15,889,772 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hopefully you can help me. I want to print the from "addr_data_list" of one of the interface name

{
    
    "fuse_image_metadata": {
        "schema_version": 2,
        "product_name": "product_X",
        "owner": "xyz",
        "ecid": "N6X1345_01_x-1_y3",
        "2d_barcode": "xxx",
        "jtag_id": "xxx",
        "last_modified_timestamp": "2021-09-07 11:01:00",
        "rule_revision": "0",
        "sku_collateral_version": "1.0",
        "dff_file": "N6X1345_01_x-1_y3_FT1_20210831_140128_ENG.json",
        "fid_image_file": "fid_image_r1.0.json",
        "image_builder_name": "fusebuild.py",
        "image_builder_version": "0.0"
    },
    "sku_fuse_data": {
        "1.A.PROD": {
            "fid_definition": {
                "sku_id": "1.TEST.DS0",
                "sku_number": "1",
                "security_state": "PROD",
                "quality_milestone": "DS0",
                "num_enabled_cores": "124",
                "ate_tp_rev": "0",
                "fuse_recipe_rev": "0",
                "vf_curve_rev": "0",
                "array_rwa_rev": "0",
                "thermal_sensor_trim": "static_presi",
                "core_disable": "static",
                "core_vf_curve": "static_safe_presi",
                "other_vf_curve": "static_safe_presi",
                "ldo_trim": "static_presi"    
            },
            "ate_sys_fuse_data": {
                "format": "binary",
                "controller_type": "MSFT_FMC",
                "addr_data_map": {
                    "0": {
                        "interface": "box_0",
                        "start_addr": 0,
                        "data": "00000000000000000000000000000001"
                    },
                    "32": {
                        "interface": "box_0",
                        "start_addr": 32,
                        "data": "11110000000000000000000000000000"
                    }
                }
            },
            "ate_bisr_fuse_data": {
                "mock_bisr_0": {
                    "format": "rle",
                    "controller_type": "BISR",
                    "addr_data_map": {
                        "0": {
                            "interface": "bisr_0",
                            "start_addr": 0,
                            "data": "100p2r150p3r50p"
                        }
                    }
                },
                "mock_bisr_1": {
                    "format": "rle",
                    "controller_type": "BISR",
                    "addr_data_map": {
                        "0": {
                            "interface": "bisr_1",
                            "start_addr": 0,
                            "data": "999p1r1p"
                        }
                    }
                }
            },
            "sfo_fuse_data": {
                "system_gsram": {
                    "format": "binary",
                    "addr_data_list": [
                        {
                            "interface": "gsram_0",
                            "start_addr": 0,
                            "data": "1111000000000001"
                        }
                    ]
                },
                "mock_bisr_0": {
                    "format": "rle",
                    "addr_data_list": [
                        {
                            "interface": "bisr_0",
                            "start_addr": 0,
                            "data": "100p2r150p3r50p"
                        }
                    ]
                },
                "mock_bisr_1": {
                    "format": "rle",
                    "addr_data_list": [
                        {
                            "interface": "bisr_1",
                            "start_addr": 0,
                            "data": "999p1r1p"
                        }
                    ]
                }
            }
        }

    }
}


What I have tried:

using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JosonParser
{
    internal class Program
    {
        static void Main(string[] args)
        {


            

            Dictionary<string, object> data = new Dictionary<string, object>();


            string jsonFilePath = @"C:\Test2\JosonParser - Copy\JosonParser\N6X1345.json";

            string json = File.ReadAllText(jsonFilePath);
            Dictionary<string, object> json_Dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
           
            


            foreach ( var item in json_Dictionary)
             {


                Console.WriteLine(item); 
				//data.Add(item.Key, item.Value);
               // Console.WriteLine("Items of data  : " + item.Key,item.Value);  //single line print
              
             }
            
         

    
         }
    }
}



#my output should be parse the element
addr_data_list

and print --->
output :
bisr_1

bisr_0

gsram_0
Posted
Updated 10-Jul-22 21:04pm

1 solution

Try converting it to actual classes - online cogenerators can take JSON and provide C#:
Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] for example gave me this:
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
    public class _0
    {
        public string @interface { get; set; }
        public int start_addr { get; set; }
        public string data { get; set; }
    }

    public class _1APROD
    {
        public FidDefinition fid_definition { get; set; }
        public AteSysFuseData ate_sys_fuse_data { get; set; }
        public AteBisrFuseData ate_bisr_fuse_data { get; set; }
        public SfoFuseData sfo_fuse_data { get; set; }
    }

    public class _32
    {
        public string @interface { get; set; }
        public int start_addr { get; set; }
        public string data { get; set; }
    }

    public class AddrDataList
    {
        public string @interface { get; set; }
        public int start_addr { get; set; }
        public string data { get; set; }
    }

    public class AddrDataMap
    {
        public _0 _0 { get; set; }
        public _32 _32 { get; set; }
    }

    public class AteBisrFuseData
    {
        public MockBisr0 mock_bisr_0 { get; set; }
        public MockBisr1 mock_bisr_1 { get; set; }
    }

    public class AteSysFuseData
    {
        public string format { get; set; }
        public string controller_type { get; set; }
        public AddrDataMap addr_data_map { get; set; }
    }

    public class FidDefinition
    {
        public string sku_id { get; set; }
        public string sku_number { get; set; }
        public string security_state { get; set; }
        public string quality_milestone { get; set; }
        public string num_enabled_cores { get; set; }
        public string ate_tp_rev { get; set; }
        public string fuse_recipe_rev { get; set; }
        public string vf_curve_rev { get; set; }
        public string array_rwa_rev { get; set; }
        public string thermal_sensor_trim { get; set; }
        public string core_disable { get; set; }
        public string core_vf_curve { get; set; }
        public string other_vf_curve { get; set; }
        public string ldo_trim { get; set; }
    }

    public class FuseImageMetadata
    {
        public int schema_version { get; set; }
        public string product_name { get; set; }
        public string owner { get; set; }
        public string ecid { get; set; }
        public string _2d_barcode { get; set; }
        public string jtag_id { get; set; }
        public string last_modified_timestamp { get; set; }
        public string rule_revision { get; set; }
        public string sku_collateral_version { get; set; }
        public string dff_file { get; set; }
        public string fid_image_file { get; set; }
        public string image_builder_name { get; set; }
        public string image_builder_version { get; set; }
    }

    public class MockBisr0
    {
        public string format { get; set; }
        public string controller_type { get; set; }
        public AddrDataMap addr_data_map { get; set; }
        public List<AddrDataList> addr_data_list { get; set; }
    }

    public class MockBisr1
    {
        public string format { get; set; }
        public string controller_type { get; set; }
        public AddrDataMap addr_data_map { get; set; }
        public List<AddrDataList> addr_data_list { get; set; }
    }

    public class Root
    {
        public FuseImageMetadata fuse_image_metadata { get; set; }
        public SkuFuseData sku_fuse_data { get; set; }
    }

    public class SfoFuseData
    {
        public SystemGsram system_gsram { get; set; }
        public MockBisr0 mock_bisr_0 { get; set; }
        public MockBisr1 mock_bisr_1 { get; set; }
    }

    public class SkuFuseData
    {
        [JsonProperty("1.A.PROD")]
        public _1APROD _1APROD { get; set; }
    }

    public class SystemGsram
    {
        public string format { get; set; }
        public List<AddrDataList> addr_data_list { get; set; }
    }
 
Share this answer
 
Comments
HelpMewithCode 11-Jul-22 6:59am    
Hi Original Griff , It possible to automated the with c# .
I mean to say Once load the JSON file it should automatically generate the Class .

If have any idea let me know
Graeme_Grant 11-Jul-22 10:09am    
Have a read of an article that I wrote: Working with JSON in C# & VB[^]

It has a list of tools at the top of the article that will do what you want... The article should answer a number of other questions for you...

enjoy
HelpMewithCode 11-Jul-22 12:55pm    
Great Article, I should any not used any library file .
Without using any library how to parse the Json file .

If you have written any article , you help me out
Graeme_Grant 11-Jul-22 21:18pm    
I missed your reply as the reply button was not used.

Thanks. The article was written to answer questions like yours above.

You're using the Newtonsoft JSON library already. It is the same library used in the article. If you don't want to use the Newtonsoft lib, there are others and they are listed in the article. If you are using DotNet Core 3.0+, pref v6.0, then you can use System.Text.Json namespace. The Newtonsoft author now works for Microsoft. It is slightly different but essentially works the same.
HelpMewithCode 12-Jul-22 2:45am    
My requirement has Changed , i am not using any Newtonsoft lib even others which u mentioned in article .


Normal c# programs without using any library Parse the Json file .

Could you help Grame_grant i am stuck

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900