1

Having problems with this code ..

        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 ();

When i Copy the complete json string into a json test site (http://jsonlint.com/) It tells me the sting is invalid ...

I'm getting all the record rows and putting them into a single json string before pushing them over to the server..

2 Answers 2

2

Shouldn't you get the result in an array form? So the final json should look like :

[{json1},{json2}..] 

Probably if you have just {json1} {json2} this is not a valid object.

Sign up to request clarification or add additional context in comments.

2 Comments

hmmmm ... so after combining into string i should put "[" in the begining and "]" at the end ? ... as well as change the " " to ","
Thanks !! tested and became a valid string .. works like a charm !!
1

Could an alternative solution be to build a collection of "MySMSLog" objects, then serialise the collection throught JSonConvert? That way you don't need to worry about getting the structure correct through your own string manipulation.

This would most likely also future proof your code on the ridiculously outlandish chance that JSON standards change, as the NewtonSoft library would be updated as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.