Reputation: 337
I am beginner to c# and windows phone programming , I have a code where I load JSON data into the Message box which I was able to do it But I want to display those data in message box to the list items in the page , I was unable to understand the API in msdn,help me from this
Programm
XAML CODE
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,12,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
</Grid>
</Grid>
CS CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
namespace JsonArray
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
string jsonString = @"{
'product': [
{
'CATEGORYNAME': [
'AshokLeyland',
'HindustanMotorsLtd',
'MahindraLtd',
'TataMotors',
'SwarajMazda'
],
'CATEGORYID': [
'1',
'2',
'3',
'4',
'6'
],
'SUBCATEGORYNAME': [
'MultiaxleVehicles',
'HippoHaulage',
'HippoTipper',
'Cargo',
'Pick-up'
],
'SUBCATEGORYID': [
'1',
'2',
'3',
'4',
'5'
],
'TYPENAME': [
'Haulage',
'Tippers',
'RigidTrucks',
'Cabs',
'DeliveryVan'
],
'TYPEID': [
'1',
'2',
'3',
'4',
'5'
]
}
],
'success': 1,
'message': 'Thetruckdetailsgettingsuccessfully'
}
"; ;
RootObject TotalList = new RootObject();
RootObject childlistonly = new RootObject();
Product prdt = new Product();
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
DataContractJsonSerializer ser = new DataContractJsonSerializer(TotalList.GetType());
TotalList = ser.ReadObject(ms) as RootObject;
string category = "";
string typename = "";
int i = 0;
int k = 0;
foreach (var d in TotalList.product)
{
foreach (var t in d.CATEGORYNAME)
{
category = category + "" + t.ToString() + "\n" + "\n" + "\n";
i++;
}
foreach (var t in d.TYPENAME)
{
typename = typename + "" + t.ToString() + "\n" + "\n" + "\n";
k++;
}
foreach (var t in d.SUBCATEGORYNAME)
{
// teststring = teststring + "" + t.ToString() + "\n" + "\n" + "\n";
i++;
}
}
MessageBox.Show("Your CATEGORYNAMES are:\n\n" + category);
MessageBox.Show("Your TYPENAMES are:\n\n" + typename);
ms.Close();
}
}
public class Product
{
public List<string> CATEGORYNAME { get; set; }
public List<string> CATEGORYID { get; set; }
public List<string> SUBCATEGORYNAME { get; set; }
public List<string> SUBCATEGORYID { get; set; }
public List<string> TYPENAME { get; set; }
public List<string> TYPEID { get; set; }
}
public class RootObject
{
public List<Product> product { get; set; }
public int success { get; set; }
public string message { get; set; }
}
}
Upvotes: 0
Views: 728
Reputation: 1532
You need to use LongListSelector or ListBox.
here are some tutorials
http://msdn.microsoft.com/en-us/library/windowsphone/design/hh202882%28v=vs.105%29.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/hh868196.aspx
http://developer.nokia.com/community/wiki/Listbox_handling_in_Windows_Phone
http://msdn.microsoft.com/en-us/library/windowsphone/design/jj735577%28v=vs.105%29.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244365%28v=vs.105%29.aspx
Also, you can check out this series -
http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners
It gives a good overview of Windows Phone
EDIT:-
In the xaml page, you need to add a LongListSelector.
A simple example-
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector Name="YourList" LayoutMode="List" IsGroupingEnabled="False">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
//Add Textblocks here
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
in code-behind -
YourList.ItemSource = YourListObject;
Upvotes: 1