c# - 适用于 Android 的 Xamarin C# : creating a json string?

标签 c# android json xamarin

这段代码有问题..

        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 字符串中,然后再将它们推送到服务器..

最佳答案

不应该以数组形式获取结果吗?所以最终的 json 应该是这样的:

[{json1},{json2}..] 

可能如果你只有 {json1} {json2} 这不是一个有效的对象。

关于c# - 适用于 Android 的 Xamarin C# : creating a json string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34810274/

相关文章:

android - Mobiscroll 的问题 - orientationchange 和 access address bar 会导致一些移动浏览器崩溃

android - Kotlin - Elvis 运算符的不当行为

arrays - JSTL 不生成 JSON 数据

c# - 如何将图像添加到用户控件?

c# - 在事件触发器中处理自定义 RoutedEvent

c# - 返回类的实例时,是否返回所有属性?

c# - 最简单的 C# 开发免费设置

java - SQLite 事务未提交

java - 使用 kafka-streams 有条件地对 json 输入流进行排序

ios - 想要创建一个json并将其发送到url