Reputation: 1397
I want to create a List Box for a Json Form a url..
I am getting Json data form a URL. I already parsed JSON data.. My JSON data Contains a Product base process in but I parsed the JSON data by this way.
Like that I followed many tutorials.. but My JSON data May products information that's not constant for example I already parsed data regarding web sites.. now I want to parse the data for movies or products But for every time I need to change the data I want it like automatically changes I already done this application on java for parsing JSON I used Hashmap.. but now in Windows I got get,set but its Working for only one product..
And One more thing.. In Android I did a List view which will like this..
So I want to display images including the data.. I already done this on Android but I want to build this in Windows..
In that I want a List Box .. like image so when I click on any item form list box .. it should display and again it should have a list or table.. In Android I did it with Listview to singleitemview in that single item view I added a Table layout..
I am stuck at these cases..
In android for one Class file i can use many xml files.. but here Xaml is main and it has only one class file..
When I am displaying data in android it is an async task.. so that right now its about flags next its about some other.. I mean if its about product for first time its for mobiles then PC..
But its not possible in windows if there tell me any way
For parsing JSON in Android I used JSON array and JSON object with Hashmap.. But in windows I found only GET,set..
Is there any way to Build like this? I am new to Windows Phone..
This Is my Json data.
{
"returnCode": "success",
"SPData": {
"result": [
{
"sdetails": [
{
"loffers": [
{
"id": "wKugoi00AOWi",
"price": "129.99",
"seller": "Google"
}
],
"O_count": 1,
"name": "google.com",
"r_count": 1,
"sku": "68190",
"url": "http://www.google.com"
},
{
"loffers": [
{
"id": "wAOWi",
"price": "129.99",
"seller": "Yahoo"
},
{
"id": "wKuAOWi",
"price": "130.99",
"seller": "Yahoo"
},
{
"id": "wKuWi",
"price": "123.99",
"seller": "Yahoo"
}
],
"offers_count": 3,
"name": "yahoo.com",
"r_count": 1,
"sku": "68190",
"url": "http://www.yahoo.com"
},
{
"loffers": [
{
"id": "7e8Wk",
"price": "99.99",
"seller": "amazon.com"
},
{
"id": "4XUaGAi",
"price": "129.99",
"seller": "amazon.com"
}
],
"offers_count": 2,
"name": "amazon.com",
"recentoffers_count": 1,
"sku": "7829033",
"url": "http://www.amazon.com"
}
],
"model": "AAA",
"weight": "1258.64",
"price_currency": "USD",
"gtins": [
"008411"
],
"mpn": "AAAAA",
"amam3_help": "To view additional merchants for this product, please upgrade your plan.",
"cat_id": "20780",
"height": "40.64",
"description": "Immersive action and endless unready to discover a... (visit site URLs for full description)",
"name": "xyz",
"features": {
"Wi-Fi Ready": "No",
"BD Live": "Yes",
"Coaxial Digital Audio Outputs": "1 [Connections that deliver audio signals to compatible A/V components in digital form. ]",
"Audio Outputs": "1 [Jacks that send audio signals to another A/V component. ]"
},
"length": "198.12",
"created_at": 1364157755,
"geo": [
"usa"
],
"width": "358.14",
"upc": "027242858411",
"ean": "0027242858411",
"category": "Blu-ray Players",
"price": "139.99",
"updated_at": 1390272838,
"manufacturer": "Sony",
"images_total": 1,
"images": [
"http://cpcstrategy.com/wp-content/uploads/2013/06/Google-logo-retargeting.jpg"
],
"brand": "Google",
"aam3_id": "4FyI",
"offers_total": 404
}
],
"total_results_count": 3,
"results_count": 3,
"code": "OK",
"offset": 0
}
}
So if I follow Get and set the Features always may not be same.. So over there I will get error.. In android I am parsing by this way..
JSONObject json_data = JSONfunctions.getJSONfromURL(url);
JSONObject json_query = json_data.getJSONObject("query");
JSONArray json_result = json_query.getJSONArray("result");
for (int i = 0; i < json_results.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject c = json_result.getJSONObject(i);
.
.
JSONArray flag = c.getJSONArray("flag");
for(int s=0;s<flag.length();s++)
{
System.out.println("URL"+flag.getString(s));
map.put("flag", flag.getString(s));
}
.
.
JSONArray json_result_site =c.getJSONArray("site");
for (int j = 0; j < c.length(); j++) {
if (j < json_result_site.length()) {
JSONObject s= json_result_site.getJSONObject(j);
map.put("url", s.optString("url"));
JSONArray json_latest = s.getJSONArray("latest");
for (int k = 0; k < json_latest.length(); k++) {
JSONObject e = json_latest.getJSONObject(k);
map.put("id", e.optString("id"));
map.put("date", e.optString("date"));
}
}
}
}
arraylist.add(map);
}
}
Is there any way to load the data in C#.. just like above..
Upvotes: 2
Views: 837
Reputation: 3331
SubList inside the main List. May be you are looking for a long list selector.
Taken from the links given below
LongListSelector which is actually an advanced ListBox that supports full data and UI virtualization, flat lists and grouped lists. It helps users to scroll through long lists of data. Basically a quick jump grid overlays the list when the user select one of the group headers after that when an item is selected from the grid the user is automatically redirected back to the long list at the selected point.
it also comes up with ways to manage headers and contents separately and efficiently.
Best Links to take a start with
The c# class structure that gets generated from your JSON data
public class Loffer
{
public string id { get; set; }
public string price { get; set; }
public string seller { get; set; }
}
public class Sdetail
{
public List<Loffer> loffers { get; set; }
public int O_count { get; set; }
public string name { get; set; }
public int r_count { get; set; }
public string sku { get; set; }
public string url { get; set; }
public int? offers_count { get; set; }
public int? recentoffers_count { get; set; }
}
public class Features
{
public string __invalid_name__Wi-Fi Ready { get; set; }
public string __invalid_name__BD Live { get; set; }
public string __invalid_name__Coaxial Digital Audio Outputs { get; set; }
public string __invalid_name__Audio Outputs { get; set; }
}
public class Result
{
public List<Sdetail> sdetails { get; set; }
public string model { get; set; }
public string weight { get; set; }
public string price_currency { get; set; }
public List<string> gtins { get; set; }
public string mpn { get; set; }
public string amam3_help { get; set; }
public string cat_id { get; set; }
public string height { get; set; }
public string description { get; set; }
public string name { get; set; }
public Features features { get; set; }
public string length { get; set; }
public int created_at { get; set; }
public List<string> geo { get; set; }
public string width { get; set; }
public string upc { get; set; }
public string ean { get; set; }
public string category { get; set; }
public string price { get; set; }
public int updated_at { get; set; }
public string manufacturer { get; set; }
public int images_total { get; set; }
public List<string> images { get; set; }
public string brand { get; set; }
public string aam3_id { get; set; }
public int offers_total { get; set; }
}
public class SPData
{
public List<Result> result { get; set; }
public int total_results_count { get; set; }
public int results_count { get; set; }
public string code { get; set; }
public int offset { get; set; }
}
public class RootObject
{
public string returnCode { get; set; }
public SPData SPData { get; set; }
}
Now debugging and checking for the RootObject in the list you are getting could give you every nested item.
Upvotes: 1
Reputation: 473
Windows phone give you the ability to do what you asked for easily by using DataBining ,all you have to do is binding your data source with XAML control and then format your XAML control template.
You are using List View in android but in windows Phone you can LongListSelector control
To know more about Data Binding and LongListSelector take a look to the following articles.
Data Binding to controls on Windows Phone
Windows Phone 8 XAML LongListSelector
Implementing the Model-View-ViewModel pattern in a Windows Phone app
Upvotes: 1