Saturday, 15 September 2012

C# JSON.NET reading string from JArray results in Blank string? -



C# JSON.NET reading string from JArray results in Blank string? -

i have dynamic json object contains property called sectionids jarray of strings.

"sectionids": [ "974ec4d7-ef2c-49cf-9ae9-4061ea832797", "974ec4d7-ef2c-49cf-9ae9-4061ea832797", "974ec4d7-ef2c-49cf-9ae9-4061ea832797" ]

however, cannot seem reference on data.

consider test code:

//section list jarray jsonsectionarray = (jarray)levelobject.sectionids; (j = 0; j < jsonsectionarray.count; j++) { console.writeline("appended : " + (string)jsonsectionarray[j]); console.writeline("direct cast: ", (string)jsonsectionarray[j]); sectionid = (string)jsonsectionarray[j]; console.writeline("json: ", sectionid); }

why "appended" non blank output?

appended : 974ec4d7-ef2c-49cf-9ae9-4061ea832797 direct cast: json:

the original problem was looping through sections find section same id, but:

private sectionview getsectionbyid(string id){ //always id == " " }

your console.writeline line has typo:

console.writeline("direct cast: ", (string)jsonsectionarray[j]);

should be:

console.writeline("direct cast: " + (string)jsonsectionarray[j]); // ------------------------------/\

or:

console.writeline("direct cast: {0}", (string)jsonsectionarray[j]);

c# json json.net

No comments:

Post a Comment