I wanted to read and parse my valid JSON file. but may be i am doing something wrong in loading hence not getting valid file
I have a json file holding valid JSON data. But when i load it with using:
(StreamReader r = new StreamReader(filePath))
{
string json = r.ReadToEnd();
}
i got something like this:
{\n \"item\": [\n {\n \"name\": \"Infinix smart 3 PLUS - 6.2\\\"water drop Display - Triple Rear Camera - 32GB ROM,2GB RAM-Fingerprint sensor-Face unlock\",\n \"url\": \"https://www.daraz.pk/products/infinix-smart-3-plus-62water-drop-display-triple-rear-camera-32gb-rom-2gb-ram-20ghz-quadcore-processor-i113246358-s1264944281.html?search=1\",\n \"price\": \"Rs. 17,999\",\n \"Image\": \"https://static-01.daraz.pk/p/2066cca3b8cf77faa08eaeedfbe69b12.jpg_340x340q80.jpg\",\n \"Detail\": \"Specifications of Infinix smart 3 PLUS - 6.2\\\"water drop Display - Triple Rear Camera - 32GB ROM,2GB RAM-Fingerprint sensor-Face unlock\\nBrand Infinix SKU 113246358_PK-1264944281 Model Smart 3 Plus\\nWhat’s in the box1xmobile with accessories\\nVIEW MORE\"\n },\n {\n \"name\": \"Honor 7C - 5.99\\\" FHD Display - 3GB RAM - 32GB ROM - Fingerprint Sensor & Face Unlock\",\n \"url\": \"https://www.daraz.pk/products/honor-7c-599-fhd-display-3gb-ram-32gb-rom-fingerprint-sensor-face-unlock-i3287863-s12693427.html?search=1\",\n \"price\": \"Rs. 18,999\",\n \"Image\": \"https://static- .........
now i used this to parse data
var jobj = JObject.Parse(json);
so i got this kind of result:
{
{
"item": [
{
"name": "Infinix smart 3 PLUS - 6.2\"water drop Display - Triple Rear Camera - 32GB ROM,2GB RAM-Fingerprint sensor-Face unlock",
"url": "https://www.daraz.pk/products/infinix-smart-3-plus-62water-drop-display-triple-rear-camera-32gb-rom-2gb-ram-20ghz-quadcore-processor-i113246358-s1264944281.html?search=1",
"price": "Rs. 17,999",
"Image": "https://static-01.daraz.pk/p/2066cca3b8cf77faa08eaeedfbe69b12.jpg_340x340q80.jpg",
"Detail": "Specifications of Infinix smart 3 PLUS - 6.2\"water drop Display - Triple Rear Camera - 32GB ROM,2GB RAM-Fingerprint sensor-Face unlock\nBrand Infinix SKU 113246358_PK-1264944281 Model Smart 3 Plus\nWhat’s in the box1xmobile with accessories\nVIEW MORE"
},
{
"name": "Honor 7C - 5.99\" FHD Display - 3GB RAM - 32GB ROM - Fingerprint Sensor & Face Unlock",
"url": "https://www.daraz.pk/products/honor-7c-599-fhd-display-3gb-ram-32gb-rom-fingerprint-sensor-face-unlock-i3287863-s12693427.html?search=1",
"price": "Rs. 18,999",
"Image": "https://static-01.daraz.pk/original/d73129d06b06db79072e07cd132684dd.jpg_340x340q80.jpg",
"Detail": "Brand Warranty\nScreen: 6.0 inches,IPS LCD capacitive touchscreen,1440 x 720\nMemory: 3GB RAM, 32GB ROM\nProcessor: Octa-core (1.8 GHz Cortex-A53) Qualcomm SDM450 Snapdragon\nCamera: 13 + 2 MP Main Camera, 8 MP Selfie Camera\nBattery:Non-removable Li-Ion 3000 mAh\nOS:Android 8.1 (Oreo)\nSIM: Dual SIM (Nano-SIM, dual stand-by)\nSpecifications of Honor 7C - 5.99\" FHD Display - 3GB RAM - 32GB ROM - Fingerprint Sensor & Face Unlock\nBrand Honor SKU HO688EL0VJIZWNAFAMZ-4039820 Phone Type Smartphone Type of battery Lithium battery Resolution HD Screen Type IPS LCD Processor Type Octa-core Operating system version Android 8.0 Oreo Warranty Policy EN 1-Year Brand Warranty (Inovi Technologies) RAM Memory 3GB Operating System Android Battery Capacity 3000 - 3999 mAh Storage Capacity 32 GB Number of SIM Slots Dual Condition New Camera Front (Megapixels) 8 MP Camera Back (Megapixels) 13 MP Video Resolution 1080p Screen Size (inches) 5.6 - 6 Inch PPI 300-400 PPI Phone Features Touchscreen,GPS,Fingerprint Sensor,Expandable Memory,WiFi,NFC Network Connections GSM,3G,4G\nWhat’s in the boxPhone, Charger, USB Cable, Manual(s), Warranty Card\nVIEW MORE"
}}
But above loaded json file never gave me results. i have tried even this to parse in my model but it always give me null:
var someType = JsonConvert.DeserializeObject<RootObj>(jobj.ToString());
When i checked on this online JSON validator: https://jsonlint.com/ I found out that i am getting double braces ("{{" and "}}") int he start and end of json file. which is not valid and must be removed. My question is where i am doing wrong why getting double curly braces in start and end although my json file was all correct.
EDIT: I have updated my complete json file which is giving double braces in result. whereas original data is with 1 curly braces in its start and end.
using (StreamReader r = new StreamReader(icon_path))
{
string json = r.ReadToEnd();
var jobj = JObject.Parse(json);
List<ObjectList> items =
JsonConvert.DeserializeObject<List<ObjectList>>(jobj.ToString());
}
Above is complete lines for parsing my data in my model
This is my model class
public class ObjectList
{
public string name { get; set; }
public string url { get; set; }
public string price { get; set; }
public string Image { get; set; }
public string Detail { get; set; }
}