none
how can i get name property out of this json file. c# RRS feed

  • Question

  • ok i been trying now for the last 3 hours to get the name prop out of this json i cut the json short because the file is huge 

    "/i/models/fc6d6067621442ebb6f4238636363d47": {
        "staffpickedAt": null,
        "files": [
          {
            "wireframeSize": 222696,
            "flag": 0,
            "osgjsUrl": "https://media.sketchfab.com/urls/fc6d6067621442ebb6f4238636363d47/dist/models/3e8d179b751d4cecb42ac61a72a83f15/file.osgjs.gz",
            "uid": "3e8d179b751d4cecb42ac61a72a83f15",
            "osgjsSize": 69069,
            "modelSize": 516884
          }
        ],
        "processingStatus": 2,
        "isPublished": true,
        "isPrivate": false,
        "viewCount": 4547,
        "averageRating": null,
        "user": {
          "uid": "4f14c4754d37418baeed49d9030992ef",
          "displayName": "Tim Bergholz - ChamferZone.com",
          "profileUrl": "https://sketchfab.com/chamferzone",
          "username": "chamferzone",
          "account": "basic",
          "avatars": {
            "uid": "fa47c68dcf6a4d43b804fa1e0fb03964",
            "images": [
              {
                "url": "https://media.sketchfab.com/avatars/fa47c68dcf6a4d43b804fa1e0fb03964/ff563f9389c242acaf2041fde2547379.jpeg",
                "height": 100,
                "width": 100,
                "size": 3459
              },
              {
                "url": "https://media.sketchfab.com/avatars/fa47c68dcf6a4d43b804fa1e0fb03964/b374de14bbe143128207f73b1d7cc3e2.jpeg",
                "height": 90,
                "width": 90,
                "size": 3009
              },
              {
                "url": "https://media.sketchfab.com/avatars/fa47c68dcf6a4d43b804fa1e0fb03964/fd80008b27b44a11a39bfd8c6f65d045.jpeg",
                "height": 48,
                "width": 48,
                "size": 1289
              },
              {
                "url": "https://media.sketchfab.com/avatars/fa47c68dcf6a4d43b804fa1e0fb03964/15c07027247f48a08b4d84eec4da9a51.jpeg",
                "height": 32,
                "width": 32,
                "size": 801
              }
            ]
          }
        },
        "reviewUrl": "https://sketchfab.com/models/fc6d6067621442ebb6f4238636363d47/review",
        "animationCount": 0,
        "metadata": {
          "animation": null,
          "textureFiles": null,
          "uvMapped": false,
          "materialCount": null,
          "scale": null,
          "line": null,
          "morph": null,
          "quad": null,
          "hasNormal": null,
          "textureCount": null,
          "triangle": null,
          "polygon": null,
          "pbrType": null,
          "hasVertexColor": null,
          "vertexCount": null,
          "hasTangent": null,
          "point": null,
          "isRigged": false,
          "totalTriangle": null,
          "sourceFiles": null
        },
        "isDeleted": false,
        "vertexCount": 21847,
        "embedUrl": "https://sketchfab.com/models/fc6d6067621442ebb6f4238636363d47/embed",
        "displayStatus": "ok",
        "editorUrl": "https://sketchfab.com/models/fc6d6067621442ebb6f4238636363d47/edit",
        "downloadCount": 0,
        "isDisabled": false,
        "preferOriginalNormalMap": false,
        "archiveSize": 816088,
        "likeCount": 83,
        "isRestricted": false,
        "publishedAt": "2016-02-02T21:10:10.206514",
        "viewerUrl": "https://sketchfab.com/3d-models/cx4-storm-fc6d6067621442ebb6f4238636363d47",
        "name": "CX4 Storm",
        "tags": [
          "chamferzone",
          "substancepainter",
          "weapon",
          "3dsmax",
          "hardsurface"
        ],
        "categories": [],
        "uid": "fc6d6067621442ebb6f4238636363d47",
        "inStore": false,
        "status": {
          "processing": "SUCCEEDED",
          "warning": {}
        },
        "processedAt": "2016-02-02T20:44:33.962013",
        "commentCount": 4,
        "currentVersion": {
          "uid": "f69fa14193424761bad5c16f6f45a8c4",
          "processedAt": null,
          "status": {
            "processing": "SUCCEEDED",
            "warning": {}
          },
          "isCurrentVersion": true,
          "createdAt": "2018-12-14T19:01:39.352098"
        },
        "options": {
          "updatedAt": "2018-12-14T19:01:39.352123",
          "background": {
            "uid": "51af6a870cce449eb75b0345feebaebb",
            "enable": true
          },
          "wireframe": {
            "color": "88888833",
            "enable": false
          },
          "materials": {
            "df56c4b9-6464-429d-b539-504549d295ba": {
              "shadeless": false,
              "name": "lense",
              "reflection": 0.3,
              "channels": {
                "RoughnessPBR": {
                  "factor": 0.18,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true
                },
                "EmitColor": {
                  "factor": 0,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true
                },
                "BumpMap": {
                  "factor": 1,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": false
                },
                "SpecularColor": {
                  "factor": 0,
                  "color": [
                    0.5,
                    0.5,
                    0.5
                  ],
                  "enable": true
                },
                "Opacity": {
                  "factor": 0.49,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true,
                  "type": "alphaBlend"
                },
                "DiffusePBR": {
                  "factor": 1,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": false
                },
                "NormalMap": {
                  "factor": 1,
                  "texture": {
                    "minFilter": "LINEAR_MIPMAP_LINEAR",
                    "textureTarget": "TEXTURE_2D",
                    "uid": "f50a7f1c03624b5f90301a14edf4e5b6",
                    "wrapS": "REPEAT",
                    "texCoordUnit": 0,
                    "magFilter": "LINEAR",
                    "internalFormat": "RGB",
                    "wrapT": "REPEAT"
                  },
                  "flipY": false,
                  "enable": true
                },
                "AlbedoPBR": {
                  "factor": 0.41000000000000003,
                  "color": [
                    0.17673768806827059,
                    0.19679242063229815,
                    0.23509307101688112
                  ],
                  "enable": true
                },
                "DiffuseIntensity": {
                  "factor": 1,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true
                },
                "SpecularF0": {
                  "factor": 0.49,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true
                },
                "GlossinessPBR": {
                  "factor": 0.8,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": false
                },
                "CavityPBR": {
                  "factor": 1,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": false
                },
                "DiffuseColor": {
                  "factor": 1,
                  "color": [
                    0.5,
                    0.5,
                    0.5
                  ],
                  "enable": true
                },
                "MetalnessPBR": {
                  "factor": 0.89,
                  "color": [
                    1,
                    1,
                    1
                  ],
                  "enable": true
                },

    among all this i tryied getting this value out of name

    "name": "CX4 Storm"

    the issue im having is i am sure it should be done like the following code i have wrote 

                var jsonContent1 = File.ReadAllText(Application.StartupPath + "\\textures.json");
                var data1 = (JObject)JsonConvert.DeserializeObject(jsonContent1);
    
                var texturesNodeKey1 = "/i/models/fc6d6067621442ebb6f4238636363d47";
                var images1 = new Dictionary<string, string>();
                foreach (var resultNode in data1[texturesNodeKey1]["name"])
                {
                    var name = resultNode["name"].ToObject<string>();
                    Name = name;
                }

    but its telling me reverence is not form of a object 

    /i/models/fc6d6067621442ebb6f4238636363d47

    then the name prop witch i have done but it dont even go into the foreachloop it just stops and exits out of that function not sure what i am doing wrong at this point 

    Monday, September 9, 2019 9:57 PM

All replies

  • Hi eelfenliedtopfan2,

    Thank you for posting here.

    You could try the following code to get value from the json file.

                var json = File.ReadAllText(@"D:\1.json");
                JObject obj = JObject.Parse(json);
                var timeZone = obj["/i/models/fc6d6067621442ebb6f4238636363d47"].ToList<JToken>();
                
                foreach (JToken j in timeZone)
                {
                    JProperty jProperty = j.ToObject<JProperty>();
                    string propertyName = jProperty.Name;
                    if(propertyName=="name")
                    {
                        Console.WriteLine(jProperty.Value);
                    }
                }

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, September 10, 2019 3:16 AM
    Moderator
  • Try this too:

    string name = data1.SelectToken( "$..['/i/models/fc6d6067621442ebb6f4238636363d47'].name" ).ToObject<string>();

    Tuesday, September 10, 2019 8:12 AM
  • You need a small change in your code.

    foreach (var resultNode in data1[texturesNodeKey1])
    {
         var name = resultNode["name"].ToObject<string>();
         Name = name;
    }


    Avik Das

    Wednesday, September 11, 2019 6:39 PM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 17, 2019 7:59 AM
    Moderator