JSON Data key wise data display in tablelayout and Textview [duplicate] - json

Json Data display in tableLayout.
I am using retrofit2 and rxjava2 to parse the JSON data.
I have to separated data show in table.
"PartyName" is the Json key. The "PartyName" value same its display one table when "PartyName" is change its object data display in another table.
PartyName value change its created new table display data.
How to its more table create please guide me?
{
"status": 1,
"0": [
{
"Cmp_Name": "ABC",
"Partyid": "18",
"ChallanNo": "-",
"PartyName": "PURCHASE MH",
"FirmName": "PURCHASE MH",
"ChallanDate": "-",
"ChallanAmount": "0.0",
"RecieveDate": "2019-03-15 00:00:00",
"RecieveAmount": "4000.0",
"DiscountAmount": "0.0",
"TDSAmount": "0.0",
"Bank": "AXIS BANK",
"ChequeNo": null,
"ChequeDate": null
},
{
"Cmp_Name": "ABC",
"Partyid": "17",
"ChallanNo": "20",
"PartyName": "PURCHASE GJ",
"FirmName": "PURCHASE GJ",
"ChallanDate": "3/11/2019",
"ChallanAmount": "1391.0",
"RecieveDate": "2019-03-15 00:00:00",
"RecieveAmount": "1391.0",
"DiscountAmount": "0.0",
"TDSAmount": "0.0",
"Bank": "AXIS BANK",
"ChequeNo": "321456",
"ChequeDate": "2019-03-15 00:00:00"
},
{
"Cmp_Name": "ABC",
"Partyid": "17",
"ChallanNo": "20",
"PartyName": "Dharama",
"FirmName": "Dharama",
"ChallanDate": "3/11/2019",
"ChallanAmount": "1391.0",
"RecieveDate": "2019-03-15 00:00:00",
"RecieveAmount": "1391.0",
"DiscountAmount": "0.0",
"TDSAmount": "0.0",
"Bank": "AXIS BANK",
"ChequeNo": "321456",
"ChequeDate": "2019-03-15 00:00:00"
},
{
"Cmp_Name": "ABC",
"Partyid": "17",
"ChallanNo": "20",
"PartyName": "Dharama",
"FirmName": "Dharama",
"ChallanDate": "3/11/2019",
"ChallanAmount": "1391.0",
"RecieveDate": "2019-03-15 00:00:00",
"RecieveAmount": "1391.0",
"DiscountAmount": "0.0",
"TDSAmount": "0.0",
"Bank": "AXIS BANK",
"ChequeNo": "321456",
"ChequeDate": "2019-03-15 00:00:00"
}
]
}
As the image below shows, different PartyName data display in different table.
How do I display the JSON key/value pair?
Please, guide me. Thanks.

Related

Json.NET serialization of multiple objects that are not in array

I have this JSON-like string.
{
"62": {
"unit_id": "431",
"staff_id": "444",
"ext_id": "0",
"barcode": "1",
"currency": "EUR",
"amount": "163.27",
"status": "Won",
"won": "43.27",
"jackpot": "120.00"
},
"63": {
"unit_id": "432",
"staff_id": "445",
"ext_id": "0",
"barcode": "258765424",
"currency": "EUR",
"amount": "0.00",
"status": "Lost",
"won": "0.00",
"jackpot": "0.00"
}
}
I want to serialize each of the properties "62", "63" to a model.
I found it. I used JObject.Parse(json) and then I can iterate over the ChildrenTokens property.

papal plus malformed_request JSON with shipping address

To show the Paypal plus iFrame (REST API) i make a Request with JSON
{
"intent": "sale",
"experience_profile_id": "XP-XXXX-XXXX-XXX-XXX",
"redirect_urls": {
"return_url": "https://www.XXXXXXX.de/bestellen.php",
"cancel_url": "https://www.XXXXXXX.de/zahlungabbruch.php"
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": "53.45",
"currency": "EUR",
"details": {
"subtotal": "49.5",
"shipping": "3.95"
}
},
"description": "Tollewolle",
"invoice_number": "",
"item_list": {
"items": [
{
"quantity": "4",
"name": "Fine Kid - 50",
"price": "8.25",
"currency": "EUR",
"sku": "8-50"
},
{
"quantity": "2",
"name": "Fine Kid - 208",
"price": "8.25",
"currency": "EUR",
"sku": "8-208"
}
]
},
"shipping_address": {
"line1": "Rechnungs Str. 41",
"city": "Flensburg",
"postal_code": "24939",
"country_code": "DE"
}
}]
}
Without the shipping_address it works fine.
With the address i get an Error 'MALFORMED_REQUEST'
I believe Shipping address is a child ob lineitems so you need to move it up a level. E.g.
"transactions": [{"amount": {"total": "53.45", "currency":
"EUR","details":{"subtotal": "49.5", "shipping":
"3.95"}},"description": "Tollewolle", "invoice_number": "",
"item_list": {"items": [{"quantity": "4", "name": "Fine Kid - 50",
"price": "8.25", "currency": "EUR", "sku": "8-50"},{"quantity": "2",
"name": "Fine Kid - 208","price": "8.25", "currency": "EUR", "sku":
"8-208"}],"shipping_address": {"line1": "Rechnungs Str. 41","city":
"Flensburg", "postal_code": "24939", "country_code": "DE"}}}]

How to show this json format in table view sections

How to show this json format in table view sections
[
{
"success": "1",
"message": "Data Listed Successfully",
"events": [
{
"event_id": "3",
"event_name": "New Years Dance Camp",
"event_type": "New Years",
"event_start_date": "2015-07-05",
"event_start_time": "03:00 pm",
"event_end_date": "2015-07-09",
"event_end_time": "10:00 pm",
"address": "anjali"
},
{
"event_id": "4",
"event_name": "Dance Meeting",
"event_type": "meeting",
"event_start_date": "2015-07-11",
"event_start_time": "08:00 am",
"event_end_date": "2015-07-15",
"event_end_time": "07:00 pm",
"address": "naroda"
},
{
"event_id": "19",
"event_name": "Dance India Dance",
"event_type": "dance",
"event_start_date": "2015-07-02",
"event_start_time": "11:37 am",
"event_end_date": "2015-07-02",
"event_end_time": "02:35 pm",
"address": "mumbai"
},
{
"event_id": "20",
"event_name": "Dance Plus",
"event_type": "dance",
"event_start_date": "2015-07-02",
"event_start_time": "11:43 am",
"event_end_date": "2015-07-02",
"event_end_time": "11:42 am",
"address": "Mumbai"
},
{
"event_id": "21",
"event_name": "Arijit Show",
"event_type": "music",
"event_start_date": "2015-07-02",
"event_start_time": "02:25 pm",
"event_end_date": "2015-07-02",
"event_end_time": "02:28 pm",
"address": "mumbai"
}
],
"shopping": [
{
"shopping_id": "3",
"item_name": "boys dresses",
"quantity": "15",
"type": "single",
"status": "",
"deadline_date": "2015-07-05"
},
{
"shopping_id": "8",
"item_name": "Cap",
"quantity": "2",
"type": "Clothes",
"status": "",
"deadline_date": "2015-07-04"
},
{
"shopping_id": "9",
"item_name": "Hat",
"quantity": "2",
"type": "Clothes",
"status": "pending",
"deadline_date": "2015-07-04"
}
],
"weekly_schedule": [
{
"weekly_id": "23",
"class": "Ballet/Jazz/Lyrical/Hip Hop",
"address": "7606 Old Alexandria Ferry Road , Clinton, MD 20735",
"start_time": "05:00 pm",
"end_time": "08:30 pm",
"days_in_week": "Sunday,",
"dates_in_week": "05,12,19,26"
},
{
"weekly_id": "24",
"class": "Tap/Jazz/Lyrical/Hip Hop",
"address": "7606 Old Alexandria Ferry Road , Clinton, MD 20735",
"start_time": "06:00 pm",
"end_time": "08:30 pm",
"days_in_week": "Wednesday,",
"dates_in_week": "01,08,15,22,29"
},
{
"weekly_id": "25",
"class": "Acro",
"address": "4891 Tesla Drive #J, Bowie, MD 20815-4317",
"start_time": "08:15 pm",
"end_time": "09:00 pm",
"days_in_week": "Wednesday,",
"dates_in_week": "01,08,15,22,29"
},
{
"weekly_id": "26",
"class": "hippop",
"address": "satellite",
"start_time": "05:30 am",
"end_time": "05:30 pm",
"days_in_week": "Sunday",
"dates_in_week": "05,12,19,26"
},
{
"weekly_id": "27",
"class": "pop ",
"address": "C.G Road",
"start_time": "04:30 am",
"end_time": "04:30 pm",
"days_in_week": "Sunday",
"dates_in_week": "05,12,19,26"
}
],
"competition": [
{
"competition_id": "12",
"event_name": "World dance",
"event_type": "weekly",
"start_date": "2015-07-04",
"start_time": "11:00 am",
"end_date": "2015-07-07",
"end_time": "12:00 pm",
"competition_date": "2015-07-04",
"address": "Rock Regency"
},
{
"competition_id": "13",
"event_name": "Just Dancer",
"event_type": "Competition",
"start_date": "2015-07-10",
"start_time": "12:00 pm",
"end_date": "2015-07-15",
"end_time": "05:00 pm",
"competition_date": "2015-07-10",
"address": "Holiday Blue"
},
{
"competition_id": "23",
"event_name": "monthly dance",
"event_type": "year",
"start_date": "2015-07-10",
"start_time": "06:15 am",
"end_date": "2015-07-15",
"end_time": "07:15 pm",
"competition_date": "2015-07-10",
"address": "abu"
},
{
"competition_id": "22",
"event_name": "Dance India Dance",
"event_type": "Dance",
"start_date": "2015-07-03",
"start_time": "01:26 pm",
"end_date": "2015-07-03",
"end_time": "01:27 pm",
"competition_date": "2015-07-03",
"address": "Mumbai"
}
],
"carpool": [
{
"carpool_id": "8",
"driver_name": "Rahul",
"source": "Mumbai",
"destination": "",
"carpool_date": "2015-07-03",
"start_time": "01:26 pm",
"end_time": "01:26 pm"
},
{
"carpool_id": "11",
"driver_name": "sonal",
"source": "Mumbai",
"destination": "",
"carpool_date": "2015-07-04",
"start_time": "08:16 am",
"end_time": "08:16 am"
}
]
}
]
You should use parseJSON to retrieve your data.
Code to parse JSON data and store it in a table:
function tableCreate(){
var data= {};
data= $.parseJSON('[{"name":"aaaa","description":"ababab"},{"name":"bbbb","description":"bcbcbc"},{"name":"cccc","description":"dcdcdc"}]');
var tableData = "";
tableData +="<table><th>Name</th><th>Description</th>";
$.each(data,
function(key, val) {
console.log(tableData);
tableData += "<tr><td>"+val.name+"</td>" ;
tableData += "<td>" + val.description + "</td></tr>";
console.log(tableData);
});
tableData +="</table>";
$('body').append(tableData);
}
Check out my sample jsfiddle link : https://jsfiddle.net/guqs9dv2/1/
You have to reformat your data to display data in tableview section wise, I think following code snippet will work for you.
NSArray *mainDataArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
NSMutableDictionary *mainDataDict = [NSMutableDictionary dictionaryWithDictionary:[mainDataArray firstObject]];
NSArray *allKeys = [mainDataDict allKeys];
if ([mainDataDict[#"success"] boolValue]==YES) {
NSMutableArray *tableArray = [NSMutableArray array]; // Use your preferred variable here to use in TableView
for (NSString *aKey in allKeys) {
if ([aKey isEqualToString:#"success"] || [aKey isEqualToString:#"message"]) {
continue;
}
NSMutableDictionary *newData = [NSMutableDictionary dictionary];
newData[#"category"] = aKey;
newData[#"items"] = mainDataDict[aKey];
[tableArray addObject:newData];
}
}
else{
// handle error
}
As per above snippet you can use "category" key for your section header title and "items" key to get respective items for category.

AngularJS variable scope

I am sure I am missing some small detail. I have a factory which reads data from the server and retrieves JSON results. Then, in my controller I do the following:
.controller('homeController', ['$scope','RecentItems', function($scope,RecentItems)
{
//scopes for the items
$scope.items={};
RecentItems.getRecentItems().done(function(data){
$scope.items = data;
console.log($scope.items);
});
}])
In the HTML template i have an ng-repeat directive > ng-repeat="item in items"
And the results don't appear in the view. console.log($scope.items) displays the data in the console however, in the view the items appears to be empty.
I know that it has to do with the variable scopes in JavaScript rather than being an AngularJS problem
THIS IS THE JSON RESULT:
[
{
"iid": "32",
"name": "Womens bag 2",
"brand": "Gucci",
"category": "Handtaschen",
"minprice": "20",
"retailprice": "400",
"duedate": "2015-06-10 21:25:00",
"description": "second bag",
"img": "images/items/1433274066696.jpg",
"current_price": "0"
},
{
"iid": "31",
"name": "Womens Bag",
"brand": "Gucci",
"category": "Handtaschen",
"minprice": "20",
"retailprice": "300",
"duedate": "2015-06-10 21:25:00",
"description": "Bag",
"img": "images/items/1433274042147.jpg",
"current_price": "0"
},
{
"iid": "30",
"name": "Watch2",
"brand": "Swiss",
"category": "Uhren",
"minprice": "20",
"retailprice": "200",
"duedate": "2015-06-10 21:25:00",
"description": "watch to test",
"img": "images/items/1433273997525.png",
"current_price": "0"
},
{
"iid": "29",
"name": "Watch",
"brand": "Swiss",
"category": "Uhren",
"minprice": "10",
"retailprice": "200",
"duedate": "2015-06-10 21:25:00",
"description": "Test",
"img": "images/items/1433273879811.png",
"current_price": "0"
}
]

Not able to fetch Weather Data from the Json Data using Angular

Is the parsing way wrong? I'm trying to get weather data
function Hello($scope, $http) {
$http
.jsonp('http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=MYKEY&callback=JSON_CALLBACK')
.success(function(data) {
var datais = JSON.stringify(data);
console.log("Datais::"+datais);
console.log("Weather::"+datais["weather"]);
})
.error(function(data){
alert("Error");
});
}
Output:
Datais::{
"data": {
"current_condition": [{
"cloudcover": "25",
"humidity": "76",
"observation_time": "09:13 AM",
"precipMM": "0.0",
"pressure": "992",
"temp_C": "9",
"temp_F": "48",
"visibility": "10",
"weatherCode": "113",
"weatherDesc": [{
"value": "Sunny"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png"
}],
"winddir16Point": "SSW",
"winddirDegree": "200",
"windspeedKmph": "13",
"windspeedMiles": "8"
}],
"request": [{
"query": "London, United Kingdom",
"type": "City"
}],
"weather": [{
"date": "2014-01-16",
"precipMM": "1.6",
"tempMaxC": "11",
"tempMaxF": "52",
"tempMinC": "5",
"tempMinF": "41",
"weatherCode": "116",
"weatherDesc": [{
"value": "Partly Cloudy"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
}],
"winddir16Point": "S",
"winddirDegree": "191",
"winddirection": "S",
"windspeedKmph": "30",
"windspeedMiles": "19"
}, {
"date": "2014-01-17",
"precipMM": "1.3",
"tempMaxC": "10",
"tempMaxF": "50",
"tempMinC": "5",
"tempMinF": "42",
"weatherCode": "116",
"weatherDesc": [{
"value": "Partly Cloudy"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
}],
"winddir16Point": "SSW",
"winddirDegree": "202",
"winddirection": "SSW",
"windspeedKmph": "27",
"windspeedMiles": "17"
}, {
"date": "2014-01-18",
"precipMM": "2.7",
"tempMaxC": "10",
"tempMaxF": "49",
"tempMinC": "4",
"tempMinF": "39",
"weatherCode": "266",
"weatherDesc": [{
"value": "Light drizzle"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0017_cloudy_with_light_rain.png"
}],
"winddir16Point": "S",
"winddirDegree": "177",
"winddirection": "S",
"windspeedKmph": "23",
"windspeedMiles": "15"
}, {
"date": "2014-01-19",
"precipMM": "1.0",
"tempMaxC": "8",
"tempMaxF": "46",
"tempMinC": "5",
"tempMinF": "41",
"weatherCode": "122",
"weatherDesc": [{
"value": "Overcast"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0004_black_low_cloud.png"
}],
"winddir16Point": "ESE",
"winddirDegree": "110",
"winddirection": "ESE",
"windspeedKmph": "13",
"windspeedMiles": "8"
}, {
"date": "2014-01-20",
"precipMM": "0.4",
"tempMaxC": "8",
"tempMaxF": "47",
"tempMinC": "1",
"tempMinF": "34",
"weatherCode": "116",
"weatherDesc": [{
"value": "Partly Cloudy"
}],
"weatherIconUrl": [{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png"
}],
"winddir16Point": "NW",
"winddirDegree": "311",
"winddirection": "NW",
"windspeedKmph": "12",
"windspeedMiles": "7"
}]
}
}
Weather::undefined
Here your datais variable is assigned the data.
if you inspect properly the json data returned as you can see in your console.log(datais);
you will be able to access weather property in datais.data.weather.
try this
console.log("Weather::"+datais.data.weather);
You will be able to access weather property.
Further weather property is an array which has weather values from today up to 4 upcoming days. you can access them in a loop
for(i=0; i<datais.data.weather.length; i++){
console.log(datais.data.weather[i]);
}
Or for example access todays weather data:
console.log(datais.data.weather[0].date);
console.log(datais.data.weather[0].tempMaxC);
console.log(datais.data.weather[0].tempMinC);
i htink you need to access the weather this way:
console.log("Weather::"+datais.data.weather);
you may use an onlne json viewer to view the structure of your data: for example: http://jsonviewer.stack.hu/ or take at look at the browser console. firebug, for example, can show the json data as tree.
And you don't need JSON.stringify. Angular does this for you:
.success(function(data) {
console.log(data.data.weather);
})

Resources