How can I parse this json with a model in Dart? - flutter

I need to parse this json with a model, but i don't know how, can someone help me please?
{
"onboarding" : [
{
"image" : "assetsblablabla",
"title" : "Your favorite delivery",
"subtitle" : "We got over 200 afiliated commerces for you"
},
{
"image" : "assets sdidj",
"title" : "Lorem ipsum dolor sit amet",
"texto_2" : ":0"
},
{
"image" : "assets/uwu/owo",
"title" : "Service on demand",
"subtitle" : "Lorem ipsum dolor sit amet"
}
]
}

Define your model as ("TestModel" is the arbitrary name I have used),
class TestModel {
var onboarding;
TestModel.fromJson(Map json) {
this.onboarding = json['onboarding'];
}
}
Then parse it as,
Widget build(BuildContext context) {
var json = {
"onboarding": [
{
"image": "assetsblablabla",
"title": "Your favorite delivery",
"subtitle": "We got over 200 afiliated commerces for you"
},
{
"image": "assets sdidj",
"title": "Lorem ipsum dolor sit amet",
"texto_2": ":0"
},
{
"image": "assets/uwu/owo",
"title": "Service on demand",
"subtitle": "Lorem ipsum dolor sit amet"
}
]
};
var fromTheModel = new TestModel.fromJson(json);
return Text(fromTheModel.onboarding[0]['image']); //displays "assetsblablabla"
}
The last line is obviously an example. You can replace the index [0] as well as the ['image'] according to your specific cases.
Is this what you are looking for?

Related

Create web hook to connect salesforce to google campaign

I'm trying to create a web-hook listener to create a new Lead when a form is filled out through google ads. Google has an option to use web-hooks to connect to CRM.
https://imgur.com/a/CCxZxJj
I followed this tutorial over here: https://www.greytrix.com/blogs/salesforce/2018/06/04/creating-an-webservice-in-salesforce-and-using-rest-api-to-externally-access-it/
and made a RestResource class
#RestResource(urlMapping='/Lead/*')
global with sharing class MyRestResource {
#HttpPost
global static String doPost(List<Map<String,String>>user_column_data) {
Map<String, String> user_data = new Map<String,String>();
for( Map<String,String> field_data : user_column_data){
user_data.put( field_data.get('column_id'), field_data.get('string_value') );
}
Lead lead = new Lead();
lead.Status = 'New';
lead.Company = user_data.get('COMPANY_NAME');
lead.Phone = user_data.get('PHONE_NUMBER');
lead.Email = user_data.get('EMAIL');
try{
insert lead;
}
catch (exception e){
System.debug('Failure');
}
return lead.Id;
}
}
I made a salesforce site and gave it access to the above class and the lead object.
https://imgur.com/a/FQl8P3K
Google Ad's also lets me send a test record so it sent this data
{
"lead_id": "TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl",
"user_column_data": [
{
"column_name": "First Name",
"string_value": "FirstName",
"column_id": "FIRST_NAME"
},
{
"column_name": "Last Name",
"string_value": "LastName",
"column_id": "LAST_NAME"
},
{
"column_name": "User Phone",
"string_value": "+16505550123",
"column_id": "PHONE_NUMBER"
},
{
"column_name": "User Email",
"string_value": "test#example.com",
"column_id": "EMAIL"
},
{
"column_name": "City",
"string_value": "Mountain View",
"column_id": "CITY"
},
{
"column_name": "Region",
"string_value": "California",
"column_id": "REGION"
},
{
"column_name": "Company Name",
"string_value": "CompanyName",
"column_id": "COMPANY_NAME"
}
],
"api_version": "1.0",
"form_id": 15016502442,
"campaign_id": 12582701989,
"google_key": "test",
"is_test": true,
"gcl_id": "TeSter-123-ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz-0123456789-AaBbCcDdEeFfGgHhIiJjKkLl",
"adgroup_id": 20000000000,
"creative_id": 30000000000
}
When checking the sandbox environment, this data doesn't exist.
Any help would be appreciated!
Last Name is a required field on Lead and, in your code, I cannot find the line where you're populating the LastName. That could be an issue.
Also, you can setup debug logs for the Guest Site User in Salesforce to see if there is any exception.

Microsoft bot framework Probelms with WebChat and Messenger

I deployed my bot to azure ,and to messenger channel .
The bot works fine on emulator , while , video card do not work on web-chat and messenger .
Also , I created an adaptive form card so the user can send data , it works fine on emulator , but
web-chat and messenger it show up but when trying to submit it show code error .
Here is the code for my video card :
public static VideoCard GetVideoCard()
{
var videoCard = new VideoCard
{
Title = "Big Buck Bunny",
Subtitle = "by the Blender Institute",
Text = "Big Buck Bunny (code-named Peach) is a short computer-animated comedy film by the Blender Institute",
//Image = new ThumbnailUrl
//{
// Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Big_buck_bunny_poster_big.jpg/220px-Big_buck_bunny_poster_big.jpg",
//},
Media = new List<MediaUrl>
{
new MediaUrl()
{
Url = "http://techslides.com/demos/sample-videos/small.mp4",
},
},
Buttons = new List<CardAction>
{
new CardAction()
{
Title = "Learn More",
Type = ActionTypes.OpenUrl,
Value = "https://peach.blender.org/",
},
},
};
return videoCard;
} .
the form card (u can see it by copy past this code to https://adaptivecards.io/designer/) :
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": 2,
"items": [
{
"type": "TextBlock",
"text": "Get In Touch",
"weight": "Bolder",
"size": "Medium"
},
{
"type": "TextBlock",
"text": "We are interested in advenced technology, we are interested in your business, we are interested in you.\n",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"text": "Don't worry, we'll never share or sell your information.",
"isSubtle": true,
"wrap": true,
"size": "Small"
},
{
"type": "TextBlock",
"text": "Your name",
"wrap": true
},
{
"type": "Input.Text",
"placeholder": "Full name",
"id": "name",
"spacing": "Medium"
},
{
"type": "TextBlock",
"text": "Your email",
"wrap": true
},
{
"type": "Input.Text",
"id": "email",
"placeholder": "youremail#example.com",
"style": "Email"
},
{
"type": "TextBlock",
"text": "Subject"
}
]
}
]
},
{
"type": "Input.Text",
"placeholder": "message",
"id": "message",
"isMultiline": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"id": "submitid"
}
]
}
For the Video Card , I have fixed it , the only one probelm is facebook is not rendering the card as it suppose to be :
sample on FB :
Sample on webchat

The filter doesnt work with one input character on b-table

i have a b-table with a filter, but the filter doesn't work when i search by one character, in my case, by the ID, but, if i introduce 2 or more numbers this work.
i check the example on bootstrap-vue and this work searching by one number, but i cant find why in my code this not work as i expected.
<div id="app">
<span label-for="search">search: </span>
<input id="search" type="text" v-model="filter" placeholder="type by search">
{{ this.filter }}
<b-table
class="mt-2"
:filter="filter"
:fields="fields"
:items="items">
</b-table>
</div>
window.onload = () => {
new Vue({
el: '#app',
data() {
return {
filter: null,
fields: [
{
key: 'isoqf_id',
label: '#'
},
{
key: 'name',
label: 'Name'
},
{
key: 'references',
label: 'references id'
}
],
items: [
{
"isoqf_id": 1,
"cerqual": {
"explanation": "Suspendisse eget ligula blandit, dignissim neque at, luctus nunc. Nulla eros odio, fringilla et diam ut, maximus euismod nibh.",
"option": "0"
},
"name": "finding #1",
"references": ["4a5f2a", "4a5f2f"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d84ee422b711a1a2eba9507",
"cerqual_option": "0"
}, {
"isoqf_id": 2,
"cerqual": {
"explanation": "",
"option": "0"
},
"name": "finding #2",
"references": ["4a5f3b", "4a5f37"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d850b3c2b711a1a2eba956f",
"cerqual_option": "0"
}, {
"isoqf_id": 3,
"cerqual": {
"explanation": "",
"option": "3"
},
"name": "finding #3",
"references": ["4a5f3b", "4a5f28"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d8517a72b711a1a2eba9679",
"cerqual_option": "3"
}]
}
},
methods: {
}
})
}
the url for test https://codepen.io/damian-garrido/pen/aboemNG
i expect i can search by the isoqf_id field, what i'm doing wrong?
The default search algorithm searches ALL fields in the items table (not just visible data). It matches by looking for anything that contains the filter string. So if you type in the digit 1 it will show all records that have the character 1 in any fields.
To limit to just certain fields, set the prop filter-included-fields to an array containing the top level property names (field names) that you want to restrict the search to. If you want to limit to just isoqf_id, then set :filter-included-fields=['isoqf_id']". To limit filtering to isoqf_id and references set `:filter-included-fields=['isoqf_id', 'references']"
See https://bootstrap-vue.js.org/docs/components/table#built-in-filtering-options

Column and table headers in same data source as data itself (json data source)

I have a json data source for a table element in my report. my json is-
[{
"line_num": {
"oldVal": "1",
"newVal": "5"
},
"product1": {
"oldVal": "product1old",
"newVal": "product1new"
}
}, {
"line_num": {
"oldVal": "4",
"newVal": "7"
},
"product2": {
"oldVal": "product2old",
"newVal": "product2new"
}
}
]
and that worked for my report, but then I needed to add the columns and table headers from the data source.
so I tried to add it as an own object in that json array above like this:
[{
"tableH": "My Table Header" ,
"col1H": "Line No." ,
"col2H": "My Product"
}, {
"line_num": {
"oldVal": "1",
"newVal": "5"
},
"product1": {
"oldVal": "product1old",
"newVal": "product1new"
}
}, {
"line_num": {
"oldVal": "4",
"newVal": "7"
},
"product2": {
"oldVal": "product2old",
"newVal": "product2new"
}
}
]
but the problem is that when there is a lot of lines larger then the page's height, the headers on the second page were null which make sense because the first obj (the headers obj) is unknown from the second line on,
but I have no idea how to pass my headers from server in another way.
the only way that worked is to add all of the headers to each obj in the array, but I can not do it because its defiantly wrong.
I also tried to put the lines as an array like this:
[{
"tableH": "My Table Header" ,
"col1H": "Line No." ,
"col2H": "My Product" ,
"Lines": [{
"line_num": {
"oldVal": "1",
"newVal": "5"
},
"product1": {
"oldVal": "product1old",
"newVal": "product1new"
}
}, {
"line_num": {
"oldVal": "4",
"newVal": "7"
},
"product2": {
"oldVal": "product2old",
"newVal": "product2new"
}
}
]
}
]
but then the fields did not pass correctly, it passed for example for - lines.line_num.newVal , the field is : ["5","7"].
I really need help with that and I'll appreciate any helpful reply.
It seems a bad idea to mix your dataset with static data. My first attempt would be to fetch static data through a scriptlet.
Otherwise, you can add the column names in a group header component and leverage the functionality provided by the isReprintHeaderOnEachPage attribute of the group.
http://jasperreports.sourceforge.net/schema.reference.html#group_isReprintHeaderOnEachPage

Firebase, Retrieving Data: Find all Titles that have 'Status' as 'Open' in Swift

Main mission is to find all Titles that have 'Status' as 'Open'
I want to get all the favorTit to an array to be used in indexPath.row
func retrieveQuery(){
var i = 0
queryRef.queryOrderedByChild("status").queryEqualToValue("Open")
.observeEventType(.ChildAdded, withBlock:
{ snapshot in
i++
self.antal = snapshot.children.allObjects.count
print(self.antal)
print(snapshot.value.objectForKey("favorTit")!)
print(i)
})
}
Firebase data
https://api.myjson.com/bins/4n5rn
{
"categories": [{
"altText": "T.ex. Städning, Disk, Tvätt, Matlagning",
"title": "Hushåll"
}, {
"altText": "T.ex. ",
"title": " "
}, {
"altText": " ",
"title": " "
}, {
"altText": " ",
"title": " "
}, {
"altText": " ",
"title": " "
}, {
"altText": " ",
"title": " "
}, {
"altText": " ",
"title": " "
}],
"favors": {
"1": {
"catId": 1,
"favorBudget": 212121,
"favorDes": "Gfdgsfdsg",
"favorDueDate": "Today",
"favorGeo": [-7.090910999999999, 107.668887],
"favorLocation": ["West Java, Indonesia"],
"favorTit": "Rätt",
"status": "Open",
"user": "2872e074-e45a-4d7a-a9c7-83fad641aa62",
"workCompletion": "In person"
},
"2": {
"catId": 1,
"favorBudget": 4000,
"favorDes": "Gfdgf",
"favorDueDate": "Today",
"favorGeo": [34.506668, -81.948334],
"favorLocation": ["Laurens County Airport, Laurens, SC 29360, USA"],
"favorTit": "Rätt",
"status": "Open",
"user": "2872e074-e45a-4d7a-a9c7-83fad641aa62",
"workCompletion": "In person"
},
"3": {
"catId": 1,
"favorBudget": 4000,
"favorDes": "Gfdgf",
"favorDueDate": "Today",
"favorGeo": [34.506668, -81.948334],
"favorLocation": ["Laurens County Airport, Laurens, SC 29360, USA"],
"favorTit": "Rätt",
"status": "Ongoing",
"user": "2872e074-e45a-4d7a-a9c7-83fad641aa62",
"workCompletion": "In person"
},
"7fd547be-7836-42e2-a74f-2f2a39baee43": {
"favorTit": "Test",
"favors": {
"furniture assmebly": {
"favorBudget": 60000,
"favorDes": "Assemly My ikea",
"favorDueDate": "Today",
"favorGeo": [39.0311755, -77.5283463],
"favorLocation": ["Polen Farm Blvd, Ashburn, VA 20148, USA"],
"favorTit": "Den ska bli fixad kom snabbt",
"workCompletion": "In person"
},
"handyman": {
"favorBudget": 43434,
"favorDes": "Install TV-Mount",
"favorDueDate": "Today",
"favorGeo": [49.0068901, 8.4036527],
"favorLocation": ["Karlsruhe, Germany"],
"favorTit": "JAllah",
"workCompletion": "In person"
},
"photography": {
"favorBudget": 6000,
"favorDes": "Jag vill ha ett album med bilder på mig och omgivningen💪 Du ska inte säga mycket under bröllopet men det ska vara vackra bilder",
"favorDueDate": "Within a week",
"favorGeo": [55.6178043, 12.98939],
"favorLocation": ["Krankajen 36, 211 12 Malmö, Sverige"],
"favorTit": "take a photo of my wedding",
"workCompletion": "In person"
},
"trädgård": {
"favorBudget": 2000,
"favorDes": "Jag vill ha den klippt med en sax",
"favorDueDate": "Within a week",
"favorGeo": [35.86166, 104.195397],
"favorLocation": ["China"],
"favorTit": "Klipp min gräsmatta",
"workCompletion": "In person"
}
},
"status": "Done"
}
},
"users": {
"2872e074-e45a-4d7a-a9c7-83fad641aa62": {
"email": "fille382#gmail.com",
"name": "lol",
"phone": "123567890",
"provider": "password"
},
"5f0fb39e-620a-4cd1-9e6a-2b7ae9baaf71": {
"email": "lol#gmail.com",
"name": "Gunn Bellander",
"phone": "0735158548",
"provider": "password"
},
"7fd547be-7836-42e2-a74f-2f2a39baee43": {
"about": "Johan my name is Filip Bellander and i am creating this beautiful app right now the about page is here so the user can quickly reach its target by writing about himself and his completions ",
"comments": {
"4354352": {
"comment": "He did everything even cleaned up after himself",
"stars": 3,
"tasktitle": "Do everything"
},
"423489054": {
"comment": "Yes very nice",
"stars": 1,
"tasktitle": "call my phone"
},
"5435486956": {
"comment": "It was very clean",
"stars": 3,
"tasktitle": "Clean room"
},
"54643654654": {
"comment": "He did a great job wiping all whipcream from the luggage",
"stars": 4,
"tasktitle": "Whipe dat"
}
},
"completed": 90,
"email": "test#gmail.com",
"name": "Filip Bellander",
"phone": "0735158548",
"posted": 81,
"provider": "password",
"rating": 5,
"reviews": 1337,
"skills": "App programmer, Visual designer DriversDriverslicenseDriverslicenseDriverslicenseDriverslicenselicense no"
},
"bdc6c3f8-764a-4468-825a-408f53695b24": {
"email": "Elisabet.bellander#gmail.com",
"name": "Elisabet Bellander",
"phone": "0721645504",
"provider": "password"
}
}
}
From your code you should already have the Open Titles array in your snapshot.
if let result = snapshot.children.allObjects as? [FIRDataSnapshot] {
self.items = result
}
Then your TableView will depend on how you are implementing it. There is some examples here and here.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
...
let cellDict = items[indexPath.row]
...
return cell
}
I was able to make an array by inserting the string at index 0 everytime it runs by using the code below
queryRef.queryOrderedByChild("status").queryEqualToValue("Open")
.observeEventType(.ChildAdded, withBlock:
{ snapshot in
self.antal = snapshot.children.allObjects.count
print(self.antal)
var titles = snapshot.value.objectForKey("favorTit") as! String
var description = snapshot.value.objectForKey("favorDes") as! String
var budget = snapshot.value.objectForKey("favorBudget") as! Double
self.openTitles.insert(titles, atIndex: 0)
self.openDescription.insert(description, atIndex: 0)
self.openBudget.insert(budget, atIndex: 0)
print(self.openTitles)
print(self.openDescription)
})