-1
var rt = JsonConvert.DeserializeObject<RootObject>(www.text);
string code = rt.Code;

value is Serializing

But multiple json objects such as:

[
    {
        "Code": "0002",
        "Name": "Inspire #9898",
        "size": "10x10",
        "Company": "inspire",
        "Description1": "Textured Grey HighQuality",
        "Description2": "Fit For Kitchen,Bathroom and PlayArea Floor",
        "Price": "250",
        "Type": "1"
    }, 
    {
        "Code": "0004",
        "Name": "Inspire #98101",
        "size": "10x10",
        "Company": "inspire",
        "Description1": "Textured Grey HighQuality",
        "Description2": "Fit For Kitchen,Bathroom and PlayArea Floor",
        "Price": "250",
        "Type": "3,1"
    }
]

gives error as

Additional text encountered after finished reading JSON content: ,. Path '', line 1, position 203. Newtonsoft.Json.JsonTextReader.Read () (at <97722d3abc9f4cf69f9e21e6770081b3>:0)

!!! I am not passing it to array !!!

[System.Serializable] 
public class RootObject 
{ 
    public string Code { get; set; } 
    public string Name { get; set; } 
    public string size { get; set; } 
    public string Company { get; set; } 
    public string Description1 { get; set; } 
    public string Description2 { get; set; } 
    public string Price { get; set; } public string Type { get; set; } 
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
akhilesh
  • 9
  • 1
  • 7

1 Answers1

0

You need to de-serialize your JSON string into a List:

Model:

public class RootObject
{
    public string Code { get; set; }
    public string Name { get; set; }
    public string size { get; set; }
    public string Company { get; set; }
    public string Description1 { get; set; }
    public string Description2 { get; set; }
    public string Price { get; set; }
    public string Type { get; set; }
}

var rt = JsonConvert.DeserializeObject<List<RootObject>>(www.text);
Rahul Sharma
  • 7,768
  • 2
  • 28
  • 54
  • Sorry i am a Newbie but it hits error as: 'List' does not contain a definition for 'Code' and no accessible extension method 'Code' accepting a first argument of type 'List' could be found – akhilesh Jan 31 '20 at 11:39
  • 1
    import `using System.Collections.Generic;` – Rahul Sharma Jan 31 '20 at 11:41
  • Already using , problem is i want to serialize lists of object,,, – akhilesh Jan 31 '20 at 11:46
  • @akhilesh Can you show us your entire code for this process? The above answer will de-serialize your `JSON` string to your `Model` as `List` – Rahul Sharma Jan 31 '20 at 11:49
  • ' [System.Serializable] public class RootObject { public string Code { get; set; } public string Name { get; set; } public string size { get; set; } public string Company { get; set; } public string Description1 { get; set; } public string Description2 { get; set; } public string Price { get; set; } public string Type { get; set; } }' – akhilesh Jan 31 '20 at 11:59
  • 'public class BindTileDetails : MonoBehaviour { int type = 0; public WWW www; void Start() { Details(); } public void Details() { sucess(); for (type = 1; type <= 5; type++) { string url = "http://*************.php?type=" + type; www = new WWW(url); StartCoroutine(WaitForRequest(www,type)); } }' – akhilesh Jan 31 '20 at 12:00
  • 'IEnumerator WaitForRequest(WWW www, int type) { yield return www; Debug.Log(type); Debug.Log(www.text); string datapass = www.text.Replace('[', ' ').Replace(']', ' '); var rt = JsonConvert.DeserializeObject(datapass); string code = rt.Code; string name = rt.Name; string Size = rt.size; string company = rt.Company; string desc1 = rt.Description1; string desc2 = rt.Description2; string price = rt.Price; string tiletype = rt.Type; }' – akhilesh Jan 31 '20 at 12:00
  • @akhilesh Please update the code in the question and not in the comments – Rahul Sharma Jan 31 '20 at 12:09