有问题,这个代码..Android的Xamarin c#:创建一个json字符串?
GlodalVariables.SoftID = "55";
WebClient client = new WebClient();
Uri uri = new Uri ("http://www.example.com/CreateEntry.php");
string folder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
Android.Content.Context myContext = Android.App.Application.Context;
try{
string smsUri = System.IO.Path.Combine (folder, "SL.db");
string myjson = "";
SQLiteDatabase Mydb = SQLiteDatabase.OpenDatabase(smsUri , null, DatabaseOpenFlags.OpenReadwrite);
ICursor SMScursor = Mydb.Query ("MySMSLog", null,null, null,null, null ,"TheDate ASC");
MySMSLog test = new MySMSLog() ;
if (SMScursor.MoveToFirst()) {
while (!SMScursor.IsAfterLast){
string number = SMScursor.GetString(SMScursor.GetColumnIndex("TheNumber"));
string name = SMScursor.GetString(SMScursor.GetColumnIndex("TheName"));
string date = SMScursor.GetString(SMScursor.GetColumnIndex("TheDate"));
string direction = SMScursor.GetString(SMScursor.GetColumnIndex("TheDirection"));
string text = SMScursor.GetString(SMScursor.GetColumnIndex("TheText"));
string id = SMScursor.GetString(SMScursor.GetColumnIndex("Id"));
test.Id = int.Parse(id);
test.TheDate = date;
test.TheDirection = direction ;
test.TheName = name;
test.TheNumber = number;
test.TheText = text;
string output = Newtonsoft.Json.JsonConvert.SerializeObject (test);
myjson = myjson + output + " ";
SMScursor.MoveToNext();
}
}
System.Console.WriteLine (myjson );
System.Console.WriteLine();
SMScursor.Close();
当我完整的JSON字符串复制到一个JSON试验场(http://jsonlint.com/) 它告诉我的刺痛是无效的......
我越来越所有的记录行并将它们放入单个json字符串,然后再将它们推送到服务器。
hmmmm ...所以在组合成字符串后,我应该把“[”放在开头和“]”末尾? ...以及将“”更改为“,” – Migz
是组成阵列 – mslliviu
谢谢!测试,并成为一个有效的字符串..作品像一个魅力! – Migz