I am working on ASP.net MVC Applciation
I am facing difficulty in preparing json response to return from a controller action method.
I need some thing like this:
{
"cityMap": {"11": "Chennai", "12": "Mumbai", "13": "Delhi"},
"rows": [
{ "SID": "1", "SNAME": "ABC", "CITY": "11" },
{ "SID": "2", "SNAME": "XYZ", "CITY": "12" },
{ "SID": "3", "SNAME": "ACX", "CITY": "13" },
{ "SID": "4", "SNAME": "KHG", "CITY": "13" },
{ "SID": "5", "SNAME": "ADF", "CITY": "12" },
{ "SID": "6", "SNAME": "KKR", "CITY": "11" }
]
}
I have cityMap values in the sortedlist names slLocations
I have row values in the form of list liStudents
I am using the following syntax to send the json response:
return JSON(new { rows=liStudents},jsonRequestBehaviour.AllowGet)
By using the above syntax , i am getting the json response like this:
{
"rows": [
{ "SID": "1", "SNAME": "ABC", "CITY": "11" },
{ "SID": "2", "SNAME": "XYZ", "CITY": "12" },
{ "SID": "3", "SNAME": "ACX", "CITY": "13" },
{ "SID": "4", "SNAME": "KHG", "CITY": "13" },
{ "SID": "5", "SNAME": "ADF", "CITY": "12" },
{ "SID": "6", "SNAME": "KKR", "CITY": "11" }
]
}
Please help on how to extend json response to above by using liStudents and liLocations
Simply add the desired cityMap property to the anonymous object that you are passing to the view:
var model = new
{
cityMap = slLocations,
rows = liStudents,
}
return JSON(model, JsonRequestBehaviour.AllowGet);
This obviously assumes that the slLocations variable is a SortedList<string, string>.
Related
I am attempting to cluster a rather large amount of data segments into Series on a timeline chart. Initially, enabling the sections on the legend plotted each data point as a filterable section, but I am unable to correctly get it working with the individual series.
Here is the code being used at present:
$.ajax({
type: "GET",
url: '/newestccoi/api/ccoi_visualization_engine.php',
dataType: "json",
data: {
sid: <?php echo $_GET['sid'] ?>
},
success: function(res) {
const time = new Highcharts.Time();
var data = [];
console.log(res);
let constructedSeries = [];
function toDateTime(secs) {
var t = new Date(1970, 0, 1);
t.setSeconds(secs);
return t;
};
let distance = 50;
for (value of Object.values(res)) {
let seriesEntry = {};
const arr_start = value[0];
const arr_end = value[value.length - 1];
//Construct our Data array with ALL entries in a given subsession
for (let i = 0; i < value.length; i++) {
let tempObj = value[i];
let obsTime = toDateTime(tempObj.seconds);
temp_data = {
name: tempObj.notes,
label: tempObj.name,
description: arr_start.sublabel,
x: obsTime.getTime(),
};
data.push(temp_data);
}
//Craft individual series entry (object) with the data object.
console.log(distance);
seriesEntry = {
dataLabels: {
allowOverlap: true,
distance: distance,
format: '<span style="color:{point.color}">● </span><span style="font-weight: bold;" > ' +
'{point.x:%M:%S}</span><br/>{point.label}'
},
marker: {
symbol: 'circle'
},
data: data
};
constructedSeries.push(seriesEntry);
//Clear data object;
data = [];
distance += 50;
}
Highcharts.chart('container', {
chart: {
type: 'timeline',
zoomType: 'x'
},
accessibility: {
screenReaderSection: {
beforeChartFormat: '<h5>{chartTitle}</h5>' +
'<div>{typeDescription}</div>' +
'<div>{chartSubtitle}</div>' +
'<div>{chartLongdesc}</div>' +
'<div>{viewTableButton}</div>'
},
point: {
valueDescriptionFormat: '{index}. {point.label}. {point.description}.'
}
},
xAxis: {
type: 'datetime',
labels: {
format: '{value:%M:%S}'
},
visible: true
},
yAxis: {
visible: false
},
legend: {
enabled: true
},
title: {
text: 'Session path timeline visualization'
},
subtitle: {
text: 'CCOI</a>'
},
colors: [
'#4185F3',
'#427CDD',
'#406AB2',
'#3E5A8E',
'#3B4A68',
'#363C46'
],
plotOptions: {
timeline:{
legendType: '',
colorByPoint: false,
showInLegend: true,
}
},
series: constructedSeries
});
},
error: function(xhr) {
//Do something to handle our error.
console.log(xhr);
}
})
Introducing the code necessary to properly display the individual Series on the legend, legendType: '', broke the timeline and returned the following Javascript Error:
Uncaught TypeError: can't access property 0, c.points is undefined
Any help on this matter would be greatly appreciated! I am including a sample piece of JSON to rid any confusion on what exactly this data looks like. If believes there's a better way of doing this in Highchart, I'm open to completely redoing it as well! I have a feeling this may have to do with the fact I am using a hacky method of changing the time scale on the timeline to Minutes and Seconds, but I am not absolutely sure.
{
"1": [
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "1",
"notes": "Student is trying to draw star in Scratch.",
"seconds": "0",
"name": "start"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "1",
"notes": null,
"seconds": "30",
"name": "independent"
}
],
"2": [
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": "Student asks for peer's help with problem.",
"seconds": "30",
"name": "start"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": null,
"seconds": "30",
"name": "interactive"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": null,
"seconds": "30",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": null,
"seconds": "90",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": null,
"seconds": "90",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "2",
"notes": null,
"seconds": "90",
"name": "interactive"
}
],
"3": [
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "3",
"notes": "Student opens Google Maps.",
"seconds": "90",
"name": "start"
},
{
"sid": "1",
"sublabel": "Problem 1",
"subsession": "3",
"notes": null,
"seconds": "135",
"name": "independent"
}
],
"4": [
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "135",
"name": "start"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "135",
"name": "interactive"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "165",
"name": "non_computing_communication"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "170",
"name": "interactive"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "170",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "170",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "180",
"name": "problem_solving"
},
{
"sid": "1",
"sublabel": null,
"subsession": "4",
"notes": null,
"seconds": "180",
"name": "interactive"
}
]
}
I attempted to follow the help of this a separate stackoveflow post that goes over the method for using multiple series within a timeline, but nothing there seemed to be the cause of why I am getting this error.
Edit
Chart when legendType is default
Chart when legendType is unset to ''
My goal is to actually have the legend correctly display 1-10 like in the second image, while actually displaying the data. When legendType is set, for some reason or another it treats every individual data object in the data array as a series, when it should actually be display the 10 series objects that are present in the array.
If this still doesn't clear things up, let me know and I'll create a codepen!
My EF Core application is returning what I imagine is context information in response instead of model. When calling the endpoint with expand option. This is the result returned:
{
"$id": "1",
"instance": null,
"container": {
"$id": "2",
"name": "SurveyQuestionValidations",
"value": null,
"next0": {
"$id": "3",
"name": "Id",
"value": 1,
"autoSelected": true
},
"autoSelected": false
},
"model": {
"$id": "4",
"schemaElements": [
{
"$id": "5",
"declaredKey": [
{
"$id": "6",
"defaultValueString": null,
"propertyKind": 1,
"type": {
"isNullable": false,
"definition": {
"$id": "7",
"name": "Int32",
"namespace": "Edm",
"typeKind": 1,
"primitiveKind": 9,
"schemaElementKind": 1,
"fullName": "Edm.Int32"
}
},
"declaringType": {
"$ref": "5"
},
"name": "Id"
}
],
"schemaElementKind": 1,
"namespace": "Data.Models",
"name": "SurveyQuestion",
"fullName": "Data.ModelsSurveyQuestion",
"typeKind": 2,
"hasStream": false,
"isAbstract": false,
"isOpen": false,
"declaredProperties": [ ...etc
This only happens when using expand. And the query is really slow but I believe it is related.
I'm very new to OpenAPI and I'm using http://editor.swagger.io to design an API.
I'm stuck in Schema with a JSON looking like following
{
"CORRELATION_ID": "10",
"CONTROL":
{
"DAS_IS_RECIPIENT": "123",
"DOCTPYE": "ert",
"PROCESS_INDICATOR": "nord"
},
"HEADER":
{
"ID": "456",
"INVOICE_NUMBER": "678",
"DMS_DOC_ID": "876",
"INVOICE_DATE": "10082020"
},
"ITEMS": [
{
"SHORT_TEXT": "123",
"LSTAR": 0,
"QUANTITY": "23"
},
{
"SHORT_TEXT": "456",
"LSTAR": 234,
"QUANTITY": "21"
}
],
"DEBITOR":
{
"ID": "444",
"FIRSTNAME": "nick",
"LASTNAME": "cantre"
},
"CREDITOR":
{
"ID": "454",
"FIRSTNAME": "ava",
"LASTNAME": "pierre"
}
}
How to create a schema according to this JSON structure?
in official docs: https://docs.graphene-python.org/projects/django/en/latest/queries/#default-queryset. In practice nothing happens. Please help. Below, for example i have just simple part of code with model Contact that have 3 fields(id, kind, value). I want the ContactType to always be filtered with kind='PHONE'.
class ContactType(DjangoObjectType):
class Meta:
model = Contact
#classmethod
def get_queryset(cls, queryset, info):
return queryset.filter(kind='PHONE')
class ContactQuery(graphene.ObjectType):
contacts = graphene.List(ContactType)
def resolve_contacts(self, info, **kwargs):
return Contact.objects.all()
The query:
{
contacts {
id
kind
value
}
}
returns:
{
"data": {
"contacts": [
{
"id": "1",
"kind": "INSTAGRAM",
"value": "technodomkz"
},
{
"id": "3",
"kind": "YOUTUBE",
"value": "UCF-HjvMMvgnhXhO4shk9i9Q"
},
{
"id": "4",
"kind": "FACEBOOK",
"value": "technodomkz"
},
{
"id": "5",
"kind": "TWITTER",
"value": "technodom_kz"
},
{
"id": "6",
"kind": "PHONE",
"value": "88000801111"
},
{
"id": "7",
"kind": "PHONE",
"value": "87272799999"
},
{
"id": "8",
"kind": "EMAIL",
"value": "callcenter#technodom.kz"
},
{
"id": "2",
"kind": "WEBSITE",
"value": "www.technodom.kz"
}
]
}
}
instead of:
{
"data": {
"contacts": [
{
"id": "6",
"kind": "PHONE",
"value": "88000801111"
},
{
"id": "7",
"kind": "PHONE",
"value": "87272799999"
}
]
}
}
For anyone looking for the answer to this question, it is answered here
Try swapping out List for DjangoConnectionField.
Looks like we need to document that get_queryset works with the DjangoConnectionField and that non-relay fields like List don't have the same magic.
This is the json I got from server I tried to create a data model for this json but didn't get in to success because of nested arrays. can anyone please help in creating data model for this jsonfile in swift. if you need I can provide the the data model I created for this json but that is not working
{
"result": [
{
"loo_id": null,
"loo_name": null,
"loo_address": null,
"loo_image": null,
"price": null,
"loo_location": null,
"type": null,
"category": [
{
"category_id": "1",
"category_name": "Hotel",
"cat_enable_image": "****images/category/hotel_clr.png",
"cat_disable_image": "****images/category/hotel_gry.png",
"status": "0"
},
{
"category_id": "5",
"category_name": "Shopping Mall",
"cat_enable_image": "****images/category/shopping_mall_clr.png",
"cat_disable_image": "****images/category/shopping_mall_gry.png",
"status": "0"
}
],
"days": null,
"timings": null,
"facilities": [
{
"facility_category_id": "1",
"facility_category_name": "Male",
"facility_category_enable_image": "****images/facility_category/male_clr.png",
"facility_category_disable_image": "****images/facility_category/male_gry.png",
"status": "0",
"facility": [
{
"facility_id": "1",
"facility_name": "Toiletten",
"enable_image": "****images/facilities/toilet_color.png",
"disable_image": "****images/facilities/toilet_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "2",
"facility_name": "Lavatory",
"enable_image": "****images/facilities/lavatory_color.png",
"disable_image": "****images/facilities/lavatory_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "3",
"facility_name": "Urinals",
"enable_image": "****images/facilities/urinals_color.png",
"disable_image": "****images/facilities/urinals_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "4",
"facility_name": "Shower",
"enable_image": "****images/facilities/shower_color.png",
"disable_image": "****images/facilities/shower_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "5",
"facility_name": "Standing Toilet",
"enable_image": "****images/facilities/standing_toilet_color.png",
"disable_image": "****images/facilities/standing_toilet_grey.png",
"count": "0",
"status": "0"
}
]
},
{
"facility_category_id": "4",
"facility_category_name": "Wheelchair",
"facility_category_enable_image": "****images/facility_category/1771138800.png",
"facility_category_disable_image": "****images/facility_category/1790222751.png",
"status": "0",
"facility": [
{
"facility_id": "12",
"facility_name": "Toiletten",
"enable_image": "****images/facilities/toilet_color.png",
"disable_image": "****images/facilities/toilet_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "13",
"facility_name": "Lavatory",
"enable_image": "****images/facilities/lavatory_color.png",
"disable_image": "****images/facilities/lavatory_grey.png",
"count": "0",
"status": "0"
},
{
"facility_id": "14",
"facility_name": "Shower",
"enable_image": "****images/facilities/shower_color.png",
"disable_image": "****images/facilities/shower_grey.png",
"count": "0",
"status": "0"
}
]
}
],
"accessbility": [
{
"accessbility_id": "1",
"accessbility_name": "Wheelchair",
"accessbility_enable_image": "****images/accessbility/wheelchair_clr.png",
"accessbility_disable_image": "****images/accessbility/wheelchair_gry.png",
"status": "0"
},
{
"accessbility_id": "2",
"accessbility_name": "Car Access",
"accessbility_enable_image": "****images/accessbility/car_access_clr.png",
"accessbility_disable_image": "****images/accessbility/car_access_gry.png",
"status": "0"
}
],
"terms_conditions": null
}
]
}