i need retrive array of json object this:
{ "mycustomname": [ { "id": 0, "item": "item 0" }, { "id": 1, "item": "item 1" } ] } instead of this:
{ [ { "id": 0, "item": "item 0" }, { "id": 1, "item": "item 1" } ] } here code i've use:
using (sqlconnection con = conection.conect()) { using (sqlcommand cmd = new sqlcommand("selpeople", con)) { con.open(); cmd.commandtype = commandtype.storedprocedure; using (sqldataadapter sda = new sqldataadapter(cmd)) { datatable dt = new datatable("mycustomname"); sda.fill(dt); list<personal> listofpeople= new list<personal>(); foreach (datarow dr in dt.rows) { personal persona = new personal(); persona.id = convert.toint32(dr["id"].tostring()); persona.name = dr["name"].tostring(); //add 1 row list listofpeople.add(persona); } jsonconvert.serializeobject(listofpeople, formatting.indented); response.write(json); } } } some nice, :)
look @ post from user
in controller change part
jsonconvert.serializeobject(listofpeople, formatting.indented); response.write(json); to:
string json = jsonconvert.serializeobject(new { mycustomname = listadodepersonal; }); response.write(json);
Comments
Post a Comment