0

I have a JSON Array String. I want to deserialize it and want to fetch each element in Asp.Net Core view page. I have tried it with the array split method but it is returning with the [] at first and end. Please help me to solve this.

My Data is :

[
    "a0xctflnmzfkxqibwgli.png",
    "hjivmkuk2jafe2cfllpv.jpg",
    "i2zcbw0se2btbiq7l4u6.gif",
    "a0rzmnbjnbtvmdv1osxo.jpg",
    "p5ok5a0ozni7lqlvoov2.gif"
]

Required Output :

a0xctflnmzfkxqibwgli.png     
hjivmkuk2jafe2cfllpv.jpg     
i2zcbw0se2btbiq7l4u6.gif     
p5ok5a0ozni7lqlvoov2.gif     
EpicKip
  • 4,015
  • 1
  • 20
  • 37
Mohammed Altaf
  • 97
  • 1
  • 1
  • 11

1 Answers1

6

presumably...

string[] values = JsonConvert.DeserializeObject<string[]>(json);

(using Json.NET)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I tried your code but it gives me the following error. Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: [. Path '', line 1, position 1. – Mohammed Altaf May 17 '17 at 11:19
  • 2
    @MohammedAltaf I did actually *run* the code before posting it... it works fine. Are you sure you copied it correctly? did you perhaps do `DeserializObject(json)` ? – Marc Gravell May 17 '17 at 12:03
  • Thanks It worked – Mohammed Altaf May 17 '17 at 12:21
  • Answer :var json = productmodel.Product.ProductImages; string[] values = JsonConvert.DeserializeObject(json); foreach (var image in values) { @image; } – Mohammed Altaf May 17 '17 at 12:24