Есть файл Json:
[
{
"domain": ".cyberforum.ru",
"expirationDate": 1649537509.797288,
"hostOnly": false,
"httpOnly": true,
"name": "__ddg1",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "fdDFdsgfgfGFDG432",
"id": 1
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1649537511.843376,
"hostOnly": false,
"httpOnly": true,
"name": "__ddg2",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "GF4234234GF",
"id": 2
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1681146260,
"hostOnly": false,
"httpOnly": false,
"name": "_ga",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "GA1.2.3574234177.1618001510",
"id": 3
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1618160660,
"hostOnly": false,
"httpOnly": false,
"name": "_gid",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "GA1.2.84654125.1618001510",
"id": 4
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1649537510,
"hostOnly": false,
"httpOnly": false,
"name": "_ym_d",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": "0",
"value": "3123432534",
"id": 5
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1618146260,
"hostOnly": false,
"httpOnly": false,
"name": "_ym_isad",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": "0",
"value": "1",
"id": 6
},
{
"domain": ".cyberforum.ru",
"expirationDate": 1649537510,
"hostOnly": false,
"httpOnly": false,
"name": "_ym_uid",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": "0",
"value": "53452324",
"id": 7
},
{
"domain": ".www.cyberforum.ru",
"expirationDate": 1649541131.924992,
"hostOnly": false,
"httpOnly": true,
"name": "__ddgid",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "FFDSertewt2454543",
"id": 8
},
{
"domain": ".www.cyberforum.ru",
"expirationDate": 1618091531.925059,
"hostOnly": false,
"httpOnly": true,
"name": "__ddgmark",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": false,
"storeId": "0",
"value": "F43245345Gfg",
"id": 9
},
{
"domain": "www.cyberforum.ru",
"hostOnly": true,
"httpOnly": false,
"name": "cfdup_timestamp",
"path": "/csharp-beginners",
"sameSite": "unspecified",
"secure": false,
"session": true,
"storeId": "0",
"value": "432545326435",
"id": 10
}
]
Преобразую его в Cookie:
List<Cookie> cookies = File.ReadLines(@"cok.json").Select(x => JsonConvert.DeserializeObject<Cookie>(x)).ToList();
Выводит ошибку:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Json.jsonFileRead' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array
List<Cookie> cookies = JsonConvert.DeserializeObject<List<Cookie>>(File.ReadAllText("cok.json"));
JsonConvert.DeserializeObject<Cookie>("[")
. У вас появилось исключение, выполнение кода остановилось, вы могли бы сразу посмотреть, чему равноx
в лямбда-выражении, но по необъеснимым причинам не стали этого делать.