web services - write web serice for android with C# -
i want write web service c# call android app
in web service wrote helloworld() method calles , convertdatatabletojsonstring converted data json downloaded converting fonction internet , probleim convertdatatabletojsonstring function it's return me thing like
"[{\"proid\":1,\"procname\":\"لبنیات\"},{\"proid\":2,\"procname\":\"لوازم بهداشتی\"},{\"proid\":3,\"procname\":\"لوازم آرایشی\"},{\"proid\":4,\"procname\":\"خشکبار\"},{\"proid\":5,\"procname\":\"نوشیدنی ها\"},{\"proid\":6,\"procname\":\"سبزیجات\"},{\"proid\":7,\"procname\":\"فرآورده های گوشتی\"}]"
the json format return not recognizable android app dont need '/' befor , after items . body can me find fanction change data table json format use in android app , thank : )
[webmethod] [scriptmethod(usehttpget = true, responseformat = responseformat.json)] public void helloworld() { javascriptserializer js = new javascriptserializer(); context.response.clear(); context.response.contenttype = "application/json"; helloworlddata data = new helloworlddata(); data.message = convertdatatabletojsonstring(db.select("select * procategory ",commandtype.text)); context.response.write(js.serialize(data.message)); } public string convertdatatabletojsonstring(datatable datatable) { system.web.script.serialization.javascriptserializer serializer = new system.web.script.serialization.javascriptserializer(); list<dictionary<string, object>> tablerows = new list<dictionary<string, object>>(); dictionary<string, object> row; foreach (datarow dr in datatable.rows) { row = new dictionary<string, object>(); foreach (datacolumn col in datatable.columns) { row.add(col.columnname, dr[col]); } tablerows.add(row); } return serializer.serialize(tablerows); }
Comments
Post a Comment