Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How do I keep double quotes from JSON data from appearing in list items?

$
0
0

I am retrieving this JSON data from my database...

{"products":[{"pid":"6","name":"Cheese","price":"$2.75","description":"Sharp Cheddar","created_at":"2013-08-21 11:38:37","updated_at":"2013-08-21 11:38:37"},{"pid":"5","name":"Milk","price":"$3.00","description":"1 gallon whole milk ","created_at":"2013-08-21 01:20:27","updated_at":"2013-08-21 01:20:27"},{"pid":"3","name":"Refined Sugar","price":"$5.00","description":"Dixie Crystal","created_at":"2013-08-20 20:23:06","updated_at":"2013-08-21 15:42:09"},{"pid":"4","name":"Unsalted Butter","price":"$4.00","description":"Unsalted butter","created_at":"2013-08-20 20:24:02","updated_at":"2013-08-21 15:41:51"}],"success":1}

I am calling the url and loading it into resource layout textview defined in ItemView.axml with this code...


namespace CallRestService
{
    [Activity (Label = "CallRestService", MainLauncher = true)]
    public class Activity1 : ListActivity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);


            string url = "http://mywebserver.com/myproductsrest/get_all_products.php";
         
            var httpReq = (HttpWebRequest)HttpWebRequest.Create (new Uri (url));

            httpReq.BeginGetResponse ((ar) => {
             
                var request = (HttpWebRequest)ar.AsyncState;
            
                using (var response = (HttpWebResponse)request.EndGetResponse (ar)) {
                 
                    var s = response.GetResponseStream ();
                 
                    var j = (JsonObject)JsonObject.Load (s);
            
                    var results = (from result in (JsonArray)j ["products"]
                        let jResult = result as JsonObject
                        select jResult ["name"].ToString()).ToArray ();
            
                    RunOnUiThread (() => {
                        ListAdapter = new ArrayAdapter (this, Resource.Layout.ItemView, results);                       
                    });
                }            

            }, httpReq);
        }
    }
}

The app loads fine and displays the list of items, however, they are all surrounded by double quotes.

Is there something easy to add/remove to trim the quotes out?

I know I should probably be creating a product class that implements a list, and then load the list from the object, but in this case, I don't want to use the extra memory. I just want to make a quick list.

Thanks in advance.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>