Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ok i got a json file the thing is huge and i only need to get certin part of this file and certin values and download url and give it a name entry depending on the hight and width of a image 2048 this is the file

https://mega.nz/#!IkQFXAJA!tcxUuw2I2WOwiaFthEztQuorCxt9xfPVXcI7aIMe_8g


and the only part i need form this whole file is these lines

JavaScript
{
        "/i/models/5c62d2818a404977a6a38057c487a1ed/textures?optimized=1": 
		{
            "count": 3,
            "results": 
			[
                {
                    "name": "NerfGun3DCoat_Roughness.png",
                    "createdAt": "2018-10-25T13:58:36.778840",
                    "images": [
                        {
                            "height": 2048,
                            "size": 1682407,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/9ee18c79e1a244c0a02d297774cf0bf5.png",
                            "width": 2048,
                            "createdAt": "2018-10-25T13:58:36.787927",
                            "updatedAt": "2018-10-25T13:58:36.787816",
                            "uid": "9ee18c79e1a244c0a02d297774cf0bf5",
                            "options": {}
                        },
                        {
                            "height": 32,
                            "size": 1134,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/9aef2d9f0eed46c6a70456dcf1127d6e.png",
                            "width": 32,
                            "createdAt": "2018-10-25T13:58:37.912949",
                            "updatedAt": "2018-10-25T13:58:37.803315",
                            "uid": "9aef2d9f0eed46c6a70456dcf1127d6e",
                            "options": {}
                        },
                        {
                            "height": 2048,
                            "size": 1027192,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/e828c971c2ae45e38cbfa979b2471f8a.jpeg",
                            "width": 2048,
                            "createdAt": "2018-10-25T22:02:02.954325",
                            "updatedAt": "2018-10-25T22:02:02.860266",
                            "uid": "e828c971c2ae45e38cbfa979b2471f8a",
                            "options": {
                                "quality": 88,
                                "format": "R"
                            }
                        },
                        {
                            "height": 1024,
                            "size": 362744,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/17e5e21be2c94520bee58e4622522502.jpeg",
                            "width": 1024,
                            "createdAt": "2018-10-25T22:02:03.047230",
                            "updatedAt": "2018-10-25T22:02:02.959950",
                            "uid": "17e5e21be2c94520bee58e4622522502",
                            "options": {
                                "quality": 92,
                                "format": "R"
                            }
                        },
                        {
                            "height": 512,
                            "size": 135546,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/c5f9b4fafeaf4d0488d9bf01e9231a1f.jpeg",
                            "width": 512,
                            "createdAt": "2018-10-25T22:02:03.150530",
                            "updatedAt": "2018-10-25T22:02:03.056399",
                            "uid": "c5f9b4fafeaf4d0488d9bf01e9231a1f",
                            "options": {
                                "quality": 95,
                                "format": "R"
                            }
                        },
                        {
                            "height": 256,
                            "size": 40878,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/90c78a4ebf6a4b80b636873e92a6dcd4.jpeg",
                            "width": 256,
                            "createdAt": "2018-10-25T22:02:03.229588",
                            "updatedAt": "2018-10-25T22:02:03.158975",
                            "uid": "90c78a4ebf6a4b80b636873e92a6dcd4",
                            "options": {
                                "quality": 95,
                                "format": "R"
                            }
                        },
                        {
                            "height": 128,
                            "size": 12125,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/10557c369d2440d2939aa77b58ee9c2f.jpeg",
                            "width": 128,
                            "createdAt": "2018-10-25T22:02:03.307893",
                            "updatedAt": "2018-10-25T22:02:03.234840",
                            "uid": "10557c369d2440d2939aa77b58ee9c2f",
                            "options": {
                                "quality": 95,
                                "format": "R"
                            }
                        },
                        {
                            "height": 64,
                            "size": 3411,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/26bd402d80c844238f09bf44110b5f5e/9cf4e43bb65246d9acb3da46899671af.jpeg",
                            "width": 64,
                            "createdAt": "2018-10-25T22:02:03.348000",
                            "updatedAt": "2018-10-25T22:02:03.312950",
                            "uid": "9cf4e43bb65246d9acb3da46899671af",
                            "options": {
                                "quality": 95,
                                "format": "R"
                            }
                        }
                    ],
                    "uid": "26bd402d80c844238f09bf44110b5f5e",
                    "updatedAt": "2018-10-25T13:58:37.923719",
                    "colorSpace": "unknown"
                },
                {
                    "name": "NerfGun3DCoat_normal_map.png",
                    "createdAt": "2018-10-25T13:58:38.931513",
                    "images": [
                        {
                            "height": 2048,
                            "size": 123774,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/6bb3fc3960294eeb881b5ccdd0fc6294.png",
                            "width": 2048,
                            "createdAt": "2018-10-25T13:58:38.937398",
                            "updatedAt": "2018-10-25T13:58:38.937322",
                            "uid": "6bb3fc3960294eeb881b5ccdd0fc6294",
                            "options": {}
                        },
                        {
                            "height": 32,
                            "size": 176,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/e6521ef3662149c8a8518250532c9239.png",
                            "width": 32,
                            "createdAt": "2018-10-25T13:58:39.944673",
                            "updatedAt": "2018-10-25T13:58:39.911689",
                            "uid": "e6521ef3662149c8a8518250532c9239",
                            "options": {}
                        },
                        {
                            "height": 2048,
                            "size": 68815,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/c758db78194d46f28a11a77109eda748.jpeg",
                            "width": 2048,
                            "createdAt": "2018-10-25T22:01:58.378918",
                            "updatedAt": "2018-10-25T22:01:58.275501",
                            "uid": "c758db78194d46f28a11a77109eda748",
                            "options": {
                                "quality": 92,
                                "format": "N"
                            }
                        },
                        {
                            "height": 1024,
                            "size": 22087,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/749e1ba2735a430aa48c755291169911.jpeg",
                            "width": 1024,
                            "createdAt": "2018-10-25T22:01:58.459488",
                            "updatedAt": "2018-10-25T22:01:58.405742",
                            "uid": "749e1ba2735a430aa48c755291169911",
                            "options": {
                                "quality": 92,
                                "format": "N"
                            }
                        },
                        {
                            "height": 512,
                            "size": 9428,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/386e8bd39a444ba1a237477396d2bb76.jpeg",
                            "width": 512,
                            "createdAt": "2018-10-25T22:01:58.525440",
                            "updatedAt": "2018-10-25T22:01:58.472420",
                            "uid": "386e8bd39a444ba1a237477396d2bb76",
                            "options": {
                                "quality": 95,
                                "format": "N"
                            }
                        },
                        {
                            "height": 256,
                            "size": 3487,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/42c25b70bd8e4b8985b35d48b876cb2c.jpeg",
                            "width": 256,
                            "createdAt": "2018-10-25T22:01:58.590537",
                            "updatedAt": "2018-10-25T22:01:58.558361",
                            "uid": "42c25b70bd8e4b8985b35d48b876cb2c",
                            "options": {
                                "quality": 95,
                                "format": "N"
                            }
                        },
                        {
                            "height": 128,
                            "size": 1303,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/cce92f80dc724ecea1ebbe086ae8dc09.jpeg",
                            "width": 128,
                            "createdAt": "2018-10-25T22:01:58.633401",
                            "updatedAt": "2018-10-25T22:01:58.594939",
                            "uid": "cce92f80dc724ecea1ebbe086ae8dc09",
                            "options": {
                                "quality": 95,
                                "format": "N"
                            }
                        },
                        {
                            "height": 64,
                            "size": 612,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/a3bd6cf1cc304da5af6087ba19a532a2/ad26b30a7ac84f71a2737858bf0eb57a.jpeg",
                            "width": 64,
                            "createdAt": "2018-10-25T22:01:58.669198",
                            "updatedAt": "2018-10-25T22:01:58.639015",
                            "uid": "ad26b30a7ac84f71a2737858bf0eb57a",
                            "options": {
                                "quality": 95,
                                "format": "N"
                            }
                        }
                    ],
                    "uid": "a3bd6cf1cc304da5af6087ba19a532a2",
                    "updatedAt": "2018-10-25T13:58:39.955835",
                    "colorSpace": "unknown"
                },
                {
                    "name": "NerfGun3DCoat_diffuse.png",
                    "createdAt": "2018-10-25T13:58:39.962991",
                    "images": [
                        {
                            "height": 2048,
                            "size": 4234581,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/1b74782aafdb4c7894f1ec4eb342a91e.png",
                            "width": 2048,
                            "createdAt": "2018-10-25T13:58:39.968816",
                            "updatedAt": "2018-10-25T13:58:39.968732",
                            "uid": "1b74782aafdb4c7894f1ec4eb342a91e",
                            "options": {}
                        },
                        {
                            "height": 32,
                            "size": 3262,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/0e5d5b6b2c2f40a4ba92d12fcbd8ba5a.png",
                            "width": 32,
                            "createdAt": "2018-10-25T13:58:41.141594",
                            "updatedAt": "2018-10-25T13:58:41.109683",
                            "uid": "0e5d5b6b2c2f40a4ba92d12fcbd8ba5a",
                            "options": {}
                        },
                        {
                            "height": 2048,
                            "size": 869718,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/c78f81ee21604fb0ab22f651a429c989.jpeg",
                            "width": 2048,
                            "createdAt": "2018-10-25T22:02:02.161390",
                            "updatedAt": "2018-10-25T22:02:01.093700",
                            "uid": "c78f81ee21604fb0ab22f651a429c989",
                            "options": {
                                "quality": 88,
                                "format": "RGB"
                            }
                        },
                        {
                            "height": 1024,
                            "size": 489505,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/12af2689f77b4681a4819d1dc2860f9a.jpeg",
                            "width": 1024,
                            "createdAt": "2018-10-25T22:02:02.246328",
                            "updatedAt": "2018-10-25T22:02:02.166053",
                            "uid": "12af2689f77b4681a4819d1dc2860f9a",
                            "options": {
                                "quality": 92,
                                "format": "RGB"
                            }
                        },
                        {
                            "height": 512,
                            "size": 212466,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/ef35950abad54537b9b4da2720844e3e.jpeg",
                            "width": 512,
                            "createdAt": "2018-10-25T22:02:02.311444",
                            "updatedAt": "2018-10-25T22:02:02.251389",
                            "uid": "ef35950abad54537b9b4da2720844e3e",
                            "options": {
                                "quality": 95,
                                "format": "RGB"
                            }
                        },
                        {
                            "height": 256,
                            "size": 70038,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/07dac67b72eb4a39bc075f74d4e1cff2.jpeg",
                            "width": 256,
                            "createdAt": "2018-10-25T22:02:02.401538",
                            "updatedAt": "2018-10-25T22:02:02.316580",
                            "uid": "07dac67b72eb4a39bc075f74d4e1cff2",
                            "options": {
                                "quality": 95,
                                "format": "RGB"
                            }
                        },
                        {
                            "height": 128,
                            "size": 22753,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/03421e7513c042f5b31ff1f3f2b5ec93.jpeg",
                            "width": 128,
                            "createdAt": "2018-10-25T22:02:02.471870",
                            "updatedAt": "2018-10-25T22:02:02.406403",
                            "uid": "03421e7513c042f5b31ff1f3f2b5ec93",
                            "options": {
                                "quality": 95,
                                "format": "RGB"
                            }
                        },
                        {
                            "height": 64,
                            "size": 6732,
                            "url": "https://media.sketchfab.com/urls/5c62d2818a404977a6a38057c487a1ed/dist/textures/d77a9fc14f1e46e39d2d33bdc7018196/e62b30429eef4827843f66181ab02e90.jpeg",
                            "width": 64,
                            "createdAt": "2018-10-25T22:02:02.521210",
                            "updatedAt": "2018-10-25T22:02:02.478423",
                            "uid": "e62b30429eef4827843f66181ab02e90",
                            "options": {
                                "quality": 95,
                                "format": "RGB"
                            }
                        }
                    ],
                    "uid": "d77a9fc14f1e46e39d2d33bdc7018196",
                    "updatedAt": "2018-10-25T13:58:41.155480",
                    "colorSpace": "unknown"
                }
            ]
        }
    }


i need to get the name the hight and the width and url if the size matches 2048

i have tryied all sorts to do this but json libary using json.net

just dont work or errors out saying have to use arrey this is the code i currently have at the moment witch defaults a null


but still dont work i lost on how to acomplish this as i never really had to use json files or parse them in c# so any help would be much appricated

What I have tried:

<pre lang="c#">            string json = File.ReadAllText(Application.StartupPath + "textures.json");
            dynamic jsonObject = JObject.Parse(json);
            JArray files = jsonObject.files;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("/i/models/5c62d2818a404977a6a38057c487a1ed/textures?optimized=1");
            foreach (dynamic file in files)
            {
                string name = file.name;
                string height = file.height;
                string url = file.url;
                string width = file.width;
                sb.AppendLine(string.Format("{0} {1} {2} {3}", name, height, url, width));
            }
            MessageBox.Show(sb.ToString());
Posted
Updated 7-Sep-19 16:33pm

1 solution

Json: A Fairly Powerful JSON Engine in a Small Package[^]

I made this for processing huge JSON.

C#
using(var reader = JsonTextReader.CreateFrom("myfile.json")) {
   reader.SkipToField("id"); // skips to the first id field it finds.
   
   var myChunk=reader.ParseSubtree(); //gets you nested objects 
}
 
Share this answer
 
Comments
elfenliedtopfan5 8-Sep-19 12:35pm    
i seem to get null when i try this
https://i.imgur.com/Bvt3Qhg.png
honey the codewitch 8-Sep-19 12:43pm    
That only accepts a flat field name. If it can't find it it returns null. It's literally looking for a field with slashes in it in your query (and that's doable in JSON) Instead you have to do like:

reader.SkipToField("foo");
reader.Read(); // i think you need this. maybe not. comment out if need be
reader.SkipToField("bar");

to navigate to "foo/bar"

I don't support JSON path in the queries, nor "xpath" here because i didn't write the JSON path part and it only works on the trees you get back from ParseSubtree()

adding, if it was supported it would be JSON Path syntax is more like "$.foo.bar"
honey the codewitch 9-Sep-19 15:13pm    
hey, I added some stuff to make it easier to use. Quick Demo in "scratch"

You can now take the reader and do like reader.SkipTo("field1","field2",0 /*array index */,"field3");

like that

Quick and dirty Demo is in "scratch" at my github

https://github.com/codewitch-honey-crisis/Json

Hope that helps. Remember that skip to field lands you on the FIELD not the Field's value, so you have to call Read() one more time if you land on NodeType of Key

Call ParseSubtree() once you're positioned on the subtree you want to parse into objects. You can then use JSON path on that.

https://github.com/codewitch-honey-crisis/Json

Here's the source link

hope that helps!

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