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     
0

1 Answer 1

6

presumably...

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

(using Json.NET)

Sign up to request clarification or add additional context in comments.

4 Comments

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.
@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<string>(json) ?
Thanks It worked
Answer :var json = productmodel.Product.ProductImages; string[] values = JsonConvert.DeserializeObject<string[]>(json); foreach (var image in values) { @image; }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.