JSON (JavaScript Object Notation)
JSON is a lightweight data-interchange format easy to read and
write.
The JSON
format is often used for serializing and transmitting structured data over a
network connection. It is used primarily to transmit data between a server and
web application,
JSON's
basic types are: Number , String ,
Boolean , Array , Object, null
Database Table :
CREATE TABLE [dbo].[User_M_FundsCategory](
[CategoryMain] [varchar](24) COLLATE
Latin1_General_CI_AS NOT NULL,
[FundOwner] [nvarchar](10) COLLATE
Latin1_General_CI_AS NULL,
[FundClass] [nvarchar](50) COLLATE
Latin1_General_CI_AS NULL,
[WebFundGroupName] [nvarchar](100) COLLATE
Latin1_General_CI_AS NULL,
[FundID] [int] NOT NULL,
[FundCode] [nvarchar](10) COLLATE
Latin1_General_CI_AS NULL,
[WebFundName] [nvarchar](102) COLLATE
Latin1_General_CI_AS NULL,
[Sedol] [nvarchar](50) COLLATE
Latin1_General_CI_AS NULL,
[Pricing] [nvarchar](50) COLLATE
Latin1_General_CI_AS NULL,
[Pricedate] [varchar](30) COLLATE
Latin1_General_CI_AS NULL,
[Bid] [decimal](30, 2) NULL,
[OfferNAV] [decimal](30, 2) NULL,
[Hyperlink] [nvarchar](289) COLLATE
Latin1_General_CI_AS NULL
)
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Fund Pricing', N'VAM', N'VAMClassBC', N'VAM Equity Funds', 15, N'VAM3D', N'US Small Cap Growth B*',
N'B10QTB8', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(22.00 AS Decimal(30, 2)), N'www.abc.com/abc.pdf')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Fund Pricing', N'VAM', N'VAMClassBC', N'VAM Equity Funds', 44, N'VAMED', N'US Micro Cap Growth B*',
N'B10QTG3', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(37.01 AS Decimal(30, 2)), N'www.abc.com/abc.pdf')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Fund Pricing', N'VAM', N'VAMClassBC', N'VAM Equity Funds', 45, N'VAMBCD', N'US Large Cap Growth B*',
N'B10QTP2', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(27.10 AS Decimal(30, 2)), N'www.abc.com/abc.pdf')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Funds (Lux) A Shares', N'VAM', N'VAMClassA', N'VAM Equity Funds', 69, N'VAMMCDA', N'US Mid Cap Growth USD A*',
N'B06FNF4', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(140.58 AS Decimal(30, 2)), N'')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'Mirror Funds', N'Mirror', N'Mirror', N'Hansard International
Limited', 142,
N'MC137', N'HIL VAM Asia Fixed Income Fund Dollar', N'MC137', N'Weekly', N'15/05/2013', CAST(0.93 AS Decimal(30, 2)), CAST(1.01 AS Decimal(30, 2)), N'')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'Mirror Funds', N'Mirror', N'Mirror', N'Old Mutual International', 144, N'OMGBWGF', N'OMGB VAM World Growth Dollar',
N'0', N'Daily', N'14/05/2013', CAST(0.65 AS Decimal(30, 2)), CAST(0.65 AS Decimal(30, 2)), N'')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Funds (Lux) A Shares', N'VAM', N'VAMClassA', N'VAM Equity Funds', 72, N'VAMSCDA', N'US Small Cap Growth A*',
N'B10QT96', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(21.69 AS Decimal(30, 2)), N'')
INSERT [dbo].[User_M_FundsCategory] ([CategoryMain], [FundOwner],
[FundClass], [WebFundGroupName], [FundID],
[FundCode], [WebFundName], [Sedol], [Pricing], [Pricedate], [Bid], [OfferNAV],
[Hyperlink])
VALUES (N'VAM Funds (Lux) A Shares', N'VAM', N'VAMClassA', N'VAM Equity Funds', 73, N'VAMSMDA', N'US Micro Cap Growth A*',
N'B10QTF2', N'Daily', N'17/05/2013', CAST(0.00 AS Decimal(30, 2)), CAST(36.72 AS Decimal(30, 2)), N'')
Interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.IO;
public class FundMainCategory
{
[DataMember(Name = "CategoryName",
Order = 1)]
public string
CategoryMain;
}
public class FundSubCategory
{
[DataMember(Name = "WebFundGroupName",
Order = 1)]
public string
WebFundGroupName;
}
public class Funddetails
{
[DataMember(Name = "CategoryMain",
Order = 1)]
public string
CategoryMain;
[DataMember(Name = "FundOwner",
Order = 1)]
public string
FundOwner;
[DataMember(Name = "FundClass",
Order = 2)]
public string
FundClass;
[DataMember(Name = "WebFundGroupName",
Order = 2)]
public string
WebFundGroupName;
[DataMember(Name = "FundID",
Order = 3)]
public int FundID;
[DataMember(Name = "FundCode",
Order = 4)]
public string
FundCode;
[DataMember(Name = "WebFundName",
Order = 5)]
public string
WebFundName;
[DataMember(Name = "Sedol",
Order = 6)]
public string Sedol;
[DataMember(Name = "Pricing",
Order = 7)]
public string
Pricing;
[DataMember(Name = "Pricedate",
Order = 8)]
public string
Pricedate;
[DataMember(Name = "Bid",
Order = 9)]
public string Bid;
[DataMember(Name = "OfferNAV",
Order = 10)]
public string
OfferNAV;
[DataMember(Name = "Hyperlink",
Order = 11)]
public string
Hyperlink;
[DataMember(Name = "MonthToDate",
Order = 12)]
public string
MonthToDate;
[DataMember(Name = "PreviousMonth",
Order = 15)]
public string
PreviousMonth;
[DataMember(Name = "ThreeMonths",
Order = 14)]
public string
ThreeMonths;
[DataMember(Name = "Currentyear",
Order = 16)]
public string
Currentyear;
[DataMember(Name = "PreviousYear",
Order = 13)]
public string
PreviousYear;
[DataMember(Name = "PreviousYearFrommCurrent",
Order = 17)]
public string
PreviousYearFrommCurrent;
[DataMember(Name = "LastThreeyears",
Order = 18)]
public string
LastThreeyears;
[DataMember(Name = "SinceLaunch",
Order = 21)]
public string
SinceLaunch;
[DataMember(Name = "LastMonthName",
Order = 20)]
public string
LastMonthName;
[DataMember(Name = "YearName",
Order = 21)]
public string
YearName;
[DataMember(Name = "LaunchDate",
Order = 22)]
public string
LaunchDate;
}
public class FundPrices
{
[DataMember(Name = "FundID",
Order = 1)]
public string FundID;
[DataMember(Name = "OfferPrice",
Order = 2)]
public string
OfferPrice;
[DataMember(Name = "PriceDate",
Order = 3)]
public string
PriceDate;
}
[ServiceContract]
public interface IRestUser
{
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "getmaincategory",
ResponseFormat = WebMessageFormat.Json)]
List<string>
GetMainCategory();
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "getsubsategory/{maincategory}",
ResponseFormat = WebMessageFormat.Json)]
List<string>
getGroupNameCategory(string maincategory);
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "getfunddetail/{maincategory}/{subcategory}",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json)]
List<Funddetails>
getFunds(string maincategory, string subcategory);
}
Service :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.ServiceModel.Activation;
using System.IO;
using System.Xml.Linq;
using System.Xml;
using System.ServiceModel;
using System.ServiceModel.Web;
[AspNetCompatibilityRequirements(RequirementsMode
= AspNetCompatibilityRequirementsMode.Allowed)]
public class RestJsonService : IRestUser
{
List<string>
_objfundpricesforgraph = new List<string>();
List<string>
_objListMaincat = new List<string>();
List<string>
_objListSubcat = new List<string>();
List<Funddetails>
_objListFund = new List<Funddetails>();
List<FundPrices>
_objListFundPrices = new List<FundPrices>();
FundMainCategory _objmaincat;
FundSubCategory _objsubcat;
Funddetails _objfnd;
FundPrices _objfndprices;
public List<string> GetMainCategory()
{
FundPriceEntities1 ctx = new
FundPriceEntities1();
var em = (from s in ctx.M_FundsCategory
orderby
s.CategoryMain.Trim() ascending
select
s.CategoryMain).Distinct();
return
em.ToList();
}
public List<string> getGroupNameCategory(string maincategory)
{
FundPriceEntities1 ctx = new
FundPriceEntities1();
var em = (from s in ctx.M_FundsCategory
where
s.CategoryMain.Trim() == maincategory.Trim()
orderby
s.WebFundGroupName.Trim() ascending
select
s.WebFundGroupName.Trim()).Distinct();
return
em.ToList();// _objListSubcat;
}
public List<Funddetails> getFunds(string
maincategory, string subcategory)
{
FundPriceEntities1 ctx = new
FundPriceEntities1();
var em = from s in ctx.M_FundsCategory
where s.CategoryMain.Trim() ==
maincategory.Trim()
&& s.WebFundGroupName.Trim() == subcategory.Trim()
select s;
foreach (M_FundsCategory
u in em)
{
_objfnd = new Funddetails();
_objfnd.CategoryMain = u.CategoryMain;
_objfnd.WebFundGroupName = u.WebFundGroupName;
_objfnd.FundID = u.FundID;
_objfnd.FundCode = u.FundCode;
_objfnd.WebFundName = u.WebFundName;
_objfnd.Sedol = u.Sedol;
_objfnd.Pricing = u.Pricing;
_objfnd.Pricedate = u.Pricedate.ToString();
_objfnd.Bid = u.Bid.ToString();
_objfnd.OfferNAV = u.OfferNAV.ToString();
_objfnd.Hyperlink = u.Hyperlink;
_objListFund.Add(_objfnd);
}
return _objListFund;
}
}
Webconfig File :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="EndpointBehavior">
<webHttp helpEnabled="true" defaultBodyStyle="Wrapped" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="RESTJSONBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="RestJsonService" behaviorConfiguration="RESTJSONBehavior">
<endpoint address="" binding="webHttpBinding" contract="IRestUser" bindingConfiguration="webHttpBindingWithJsonP" behaviorConfiguration="EndpointBehavior" />
</service>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="FundPriceEntities1" connectionString="Database Connection String" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Right click on service and view in browser
Category Page:
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<head>
<meta name="viewport"
content="width=device-width,
initial-scale=1">
<link href="Scripts/jquery.mobile-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.structure-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.theme-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<script src="Scripts/jquery-1.8.3.min.js"
type="text/javascript"></script>
<script src="Scripts/jquery.mobile-1.2.1.min.js"
type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$.ajax({
async: false,
type: "GET",
contentType: "application/json;
charset=utf-8",
url: 'RestJsonService.svc/getmaincategory',
data: {},
dataType: "json",
error: function
(msg) {
alert('Service call failed: ' + msg.status + ' Type :' + msg.statusText);
},
success: function (msg) {
var
result = msg.GetMainCategoryResult;
var
items = [];
$.each(result, function (index, output) {
$('#ul_Maincategory').append($('<li/>', {
}).append($('<a/>', {
'href': 'SubCat.htm?c='
+ output,
'data-transition': 'slide',
'data-ajax': 'false',
'text': output
})));
});
$("#ul_Maincategory").listview("refresh");
}
});
});
</script>
</head>
<body>
<div data-role="page" id="HomePage" data-title="Home Page" >
<div data-role="header"
>
<a href="index.htm"
data-role="button"
style="width:100px;" data-icon="refresh">Refresh</a>
</div>
<div data-role="content" >
<h2 style="text-align:center">Welcome</h2>
<ul data-role="listview" data-inset="true"
data-theme="a" id="ul_Maincategory" data-filter="false">
</ul>
</div>
<div data-role="footer"
style="text-align:center">
<h4 style="cursor:hand" id="FLink"></h4>
</div>
</div>
</body>
</html>
Sub
Category Page :
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<head>
<meta name="viewport"
content="width=device-width,
initial-scale=1">
<link href="Scripts/jquery.mobile-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.structure-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.theme-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<script src="Scripts/jquery-1.8.3.min.js"
type="text/javascript"></script>
<script src="Scripts/jquery.mobile-1.2.1.min.js"
type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var Category = getUrlVars()["c"];
$.ajax({
beforeSend: function () {
$.mobile.loading('show'); },
complete: function () {
$.mobile.loading('hide'); },
async: false,
type: "GET",
contentType: "application/json;
charset=utf-8",
url: 'RestJsonService.svc/getsubsategory/'
+ Category,
data: {},
dataType: "json",
error: function (msg) {
alert('Service call failed: ' + msg.status + ' Type :' + msg.statusText);
},
success: function (msg) {
var
result = msg.getGroupNameCategoryResult;
var
items = [];
$.each(result, function (index, output) {
$('#ul_Subcategory').append($('<li/>', {
}).append($('<a/>', {
'href': 'Funds.htm?c='
+ Category + '&sc=' + output,
'data-transition': 'slide',
'data-ajax': 'false',
'text':
output
})));
});
$("#ul_Subcategory").listview("refresh");
$("#ul_Maincategory li a").click(function () {
$.mobile.loading('show');
});
$(window).unload(function () {
$.mobile.loading('hide');
});
}
});
function getUrlVars() {
var vars = [], hash;
var hashes =
window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var
i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
});
</script>
</head>
<body>
<div data-role="page" id="HomePage" data-title="Home Page">
<div data-role="header">
<a href="#HomePage" data-rel="back" data-icon="back" style="float:left" id="ID_SubCate" data-transition="slide">Back</a>
<a id="ID_Home"
rel="external" href="index.htm" data-icon="home">Home</a>
</div>
<div data-role="content"
>
<h4>Welcome</h4>
<ul data-role="listview" data-inset="true" id="ul_Subcategory" data-theme="a"
data-filter="false">
</ul>
</div>
<div data-role="footer"
style="text-align:center">
</div>
</div>
</body>
</html>
Fund detail
Page :
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<head>
<style>
.pcontent
{
padding-top:2px;
padding-bottom:1px;
font-size:15px;
}
.pcontentmore
{
color:Red;
}
</style>
<meta name="viewport"
content="width=device-width,
initial-scale=1">
<link href="Scripts/jquery.mobile-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.structure-1.3.1.css"
rel="stylesheet"
type="text/css"
/>
<link href="Scripts/jquery.mobile.theme-1.3.1.css"
rel="stylesheet"
type="text/css" />
<script src="Scripts/jquery-1.8.3.min.js"
type="text/javascript"></script>
<script src="Scripts/jquery.mobile-1.2.1.min.js"
type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$(document).ajaxSend(function () {
$.mobile.loading('show');
});
$(document).ajaxComplete(function () {
$.mobile.loading('hide');
});
$('#ul_Maincategory').html();
var Category = getUrlVars()["c"];
var SubCategory = getUrlVars()["sc"];
$.ajax({
beforeSend: function () {
$.mobile.showPageLoadingMsg(); },
complete: function () {
$.mobile.hidePageLoadingMsg() },
type: "GET",
contentType: "application/json;
charset=utf-8",
url: 'RestJsonService.svc/getfunddetail/'
+ Category + '/' + SubCategory,
data: strJSONFilterCriteria,
dataType: "json",
error: function (msg) {
alert('Service call failed: ' + msg.status + ' Type :' + msg.statusText);
},
success: function (msg) {
var
result = msg.getFundsResult;
var
items = [];
$.each(result, function (index, output) {
var
InnerHtml = '<h3>' + output.WebFundName
+ '</h3>';
if (output.CategoryMain != "Mirror
Funds") {
InnerHtml =
InnerHtml + '<p style="font-size:15px;"
class="pcontent">Sedol Code : ' + output.Sedol + '</p>';
InnerHtml =
InnerHtml + '<p style="font-size:15px;"
class="pcontent">Pricing : ' + output.Pricing + '</p>';
InnerHtml =
InnerHtml + '<p style="font-size:15px;"
class="pcontent">LastPrice Date : ' + output.Pricedate + '</p>';
InnerHtml =
InnerHtml + '<p style="font-size:15px;"
class="pcontent">NAV : ' + output.OfferNAV + '</p>';
InnerHtml =
InnerHtml + '<p
style="padding-top:3px"></p>';
InnerHtml =
InnerHtml + '<p
class="pcontentmore"><img
src="img/btn_more_update.gif" /> </p>';
}
else {
InnerHtml =
InnerHtml + '<p
style="font-size:15px;"
class="pcontent">Fund Code :' + output.FundCode + '</p>';
InnerHtml =
InnerHtml + '<p
style="font-size:15px;"
class="pcontent">Pricing : ' + output.Pricing + '</p>';
InnerHtml = InnerHtml +
'<p
style="font-size:15px;"
class="pcontent">LastPrice Date :' +
output.Pricedate + '</p>';
InnerHtml =
InnerHtml + '<p
style="font-size:15px;"
class="pcontent">Bid : ' + output.Bid + '</p>';
InnerHtml =
InnerHtml + '<p
style="font-size:15px;"
class="pcontent">Offer :' + output.OfferNAV + '</p>';
InnerHtml =
InnerHtml + '<p
style="padding-top:3px"></p>';
InnerHtml = InnerHtml + '<p class="pcontentmore"><img
src="img/btn_more_update.gif" /> </p>';
}
$('#ul_Maincategory').append($('<li/>', {
}).append($('<a/>', {
'href': 'Funddetails.htm?fid='
+ output.FundID,
'html': InnerHtml,
'data-transition': 'slide',
'data-ajax': 'false'
})));
$("#Fund_Title").text(output.WebFundGroupName)
});
$("#ul_Maincategory").listview("refresh");
$("#ul_Maincategory li a").click(function () {
$.mobile.loading('show');
});
$(window).unload(function () {
$.mobile.loading('hide');
});
}
});
// Read a page's GET URL variables and
return them as an associative array.
function getUrlVars() {
var vars = [], hash;
var hashes =
window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var
i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
});
</script>
</head>
<body>
<div data-role="page" id="HomePage" data-title="Home Page" data-dom-cache="true">
<div data-role="header">
<a href="#HomePage" data-rel="back" data-icon="back" style="float:left" id="A1" data-transition="slide">Back</a>
<a id="ID_Home" rel="external"
href="index.htm"
data-icon="home">Home</a>
</div>
<div data-role="content"
>
<h4
id="Fund_Title"></h4>
<ul data-role="listview" data-inset="true" data-theme="a"
id="ul_Maincategory">
</ul>
</div>
<div data-role="footer"
style="text-align:center">
</div>
</div>
</body>
</html>
OutPut :
No comments :
Post a Comment