Angular 5 , display json in html - html

In my project in Angular 5, I want to display in HTML code parameter "default_price":100, but my code display all default_price.
component.ts
this.ws.getAllProduct().subscribe(
products => {
this.products = products.map((product) => {
return new Product(product);
});
}
);
component.html
<div class="row">
<div class="input-field col s12">
<label for="unit_price" *ngFor="let item of products">{{item.default_price}}</label>
<input formControlName="unit_price" id="unit_price" type="number" class="validate" placeholder="unit_price">
</div>
</div>
Json:
{
"StatusCode": 0, "StatusMessage": "OK", "StatusDescription":
[
{
"product_id": "1",
"product_name": "Product1",
"description": "Product1",
"default_price": 50,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:26:17.000Z",
"active": 1
},
{
"product_id": "2",
"product_name": "Product2",
"description": "Product2",
"default_price": 60,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:17.000Z",
"active": 1
},
{
"product_id": "3",
"product_name": "Product3",
"description": "Product3",
"default_price": 80,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:22.000Z",
"active": 1
},
{
"product_id": "4",
"product_name": "Product4",
"description": "Product4",
"default_price": 100,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:25:54.000Z",
"active": 1
},
{
"product_id": "5",
"product_name": "Product5",
"description": "Product5",
"default_price": 120,
"lastmoduserid": "31",
"lastmoddtm": "2018-02-06T13:35:27.000Z",
"active": 1
}
]
}
I want to display in html code only "product_id":"4", "product_name":"Product4".
Can you suggest me some idea?

You don't need ngFor if you need to display particular object, you can use array.find() to find particular element in the array

from your json, products.StatusDescription is the array

Related

extract data from object array from json field in mysql 8

I would like through a sql query to extract data from a json field in mysql8
TABLE :
id | int
game_at | datetime
scores | json
Registrations in mysql :
id : 1,
game_at : 2022-11-04 15:53:00
scores :
[
{
"tr": "4",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "67"
},
{
"tr": "7",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "71"
},
{
"tr": "7",
"tt": "10",
"type": "beta",
"week": 44,
"id": "67"
},
{
"tr": "8",
"tt": "10",
"type": "beta",
"week": 44,
"id": "71"
}
]
id : 2,
game_at : 2022-11-05 16:53:00
scores :
[
{
"tr": "2",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "6",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "71"
},
{
"tr": "3",
"tt": "10",
"type": "beta",
"week": 45,
"id": "67"
},
{
"tr": "7",
"tt": "10",
"type": "beta",
"week": 45,
"id": "71"
}
]
id : 3,
game_at : 2022-11-04 17:53:00
scores :
[
{
"tr": "10",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "6",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "71"
},
{
"tr": "9",
"tt": "10",
"type": "beta",
"week": 45,
"id": "67"
},
{
"tr": "1",
"tt": "10",
"type": "beta",
"week": 45,
"id": "71"
}
]
I tried this to start :
$sql ='SELECT scores->"$.type"
FROM adresse
WHERE scores->"$.poliste" = "67"
';
but it returns null?
For example, I would like to retrieve all the values ​​where:
id: 67
type: alpha
{
"tr": "4",
"tt": "10",
"type": "alpha",
"week": 44,
"id": "67"
},
{
"tr": "2",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
{
"tr": "10",
"tt": "10",
"type": "alpha",
"week": 45,
"id": "67"
},
to create a table
I read that there is JSON_TABLE or substring_index but I don't understand how it works. An example would allow me to move forward Thank you in advance

Error parsing a specific JSON file in Snowflake with File Format

I have created a Stage and File Format in Snowflake which works with all my other JSON files except this, which throws an error:
Error parsing JSON: misplaced { File 'rooms.json.gz', line 1,
character 2 Row 0, column $1
I am using the same query that I am using for other files.
SELECT $1
FROM #MySchema.MY_STAGE/rooms.json.gz
;
What is wrong with the structure of this specific JSON file?
{
"rooms": [
{
"area": 131.49,
"longDescription": "",
"dateCreated": 1589908063390,
"reservable": false,
"name": "E249",
"remoteInfo": "",
"description": "",
"id": 2,
"type": {
"hexColor": "c16058",
"contentFlag": 1,
"cost": 0.0,
"dateCreated": 1308610520717,
"color": {},
"name": "BREAK ROOM",
"occupiable": false,
"id": 120,
"parkingSpace": false,
"dateUpdated": 1591818585913,
"typeCode": ""
},
"floor": {
"area": 25312.9878,
"dateCreated": 1589907703870,
"drawingAvailable": true,
"interiorGross": 0.0,
"name": "2",
"leaseArea": 0.0,
"id": 12,
"building": {
"address": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"city": "Some City",
"street": "Some Drive",
"postalCode": "00000",
"state": {
"country": {
"defaultSelected": true,
"subdivisionCategoryName": "state",
"alpha2Code": "US",
"isoCode": "US",
"name": "United States of America (the)",
"id": 223
},
"defaultSelected": false,
"code": "XX",
"name": "Some State",
"id": 66,
"categoryName": "state"
}
},
"code": "B2",
"dateCreated": 1589907508020,
"metric": false,
"name": "Some name",
"location": {},
"revitLink": "",
"id": 45,
"dateUpdated": 1601315841453,
"costCenters": []
},
"dateUpdated": 1600441936663
},
"capacity": 0,
"dateUpdated": 1600441936960
}
]
}
Edit: Screenshot from Notepad++ with all characters enabled

How to call API request for each key of a JSON Object separately in REACT JS by loop?

I have JSON Object data stored in state of mycart in the following format:
(this is the data of products which are grouped by their CompanyNames)
{
"Master Automotives": [
{
"SparePartID": "43",
"Name": "Oil and Lubricants",
"Price": "4500",
"VendorID": "48",
"CompanyName": "Master Automotives",
"Qty": 1,
"TotalPrice": "4500"
},
{
"SparePartID": "45",
"Name": "Lights",
"Price": "2300",
"VendorID": "48",
"CompanyName": "Master Automotives",
"Qty": 1,
"TotalPrice": "2300"
}
],
"Repair Solutions": [
{
"SparePartID": "47",
"Name": "Steering Wheel",
"Price": "1500",
"VendorID": "60",
"CompanyName": "Repair Solutions",
"Qty": 1,
"TotalPrice": "1500"
}
],
"FiveStar Automotives": [
{
"SparePartID": "51",
"Name": "Brakes",
"Price": "234",
"VendorID": "70",
"CompanyName": "FiveStar Automotives",
"Qty": 1,
"TotalPrice": "234"
},
{
"SparePartID": "53",
"Name": "Clutch",
"Price": "999",
"VendorID": "70",
"CompanyName": "FiveStar Automotives",
"Qty": 1,
"TotalPrice": "999"
},
{
"SparePartID": "55",
"Name": "LED",
"Price": "288",
"VendorID": "70",
"CompanyName": "FiveStar Automotives",
"Qty": 1,
"TotalPrice": "288"
}
]
}
Now I wanna place separate orders for each Company. Like if Company A : "Master Automotives" has 2 products I wanna call API to place its order separately
and then call the API again for Company B: "Repair Soltions" which has 1 product and place its order. And so on for all the companies which are present in mycart JSON object.
I wanna loop through the mycart Object according to Company Names and call APIs separately for each Company in a same function. (This Object mycart can have multiple companies. dynamic).
This is how My API call will be. I just dont know how to loop through my JSON Object within this function:
placeOrder()
{
const orderData = {
CustomerID: this.state.customer.CustomerID,
TotalPrice: this.state.totalPrice }
//TotalPrice is each Company's items' total
//nested API call
axios.post('http://localhost/Auth/api/customers/create_order.php', orderData)
.then((res) => {
console.log(res.data);
this.setState({orderID: res.data.oid});
const cartOrder = this.state.mycart;
alert("Congratulations! Your Order is Confirmed");
return axios.post('http://localhost/Auth/api/customers/insert_order_details.php', cartOrder)
.then((result) => {
alert("Your all order items added to order details table");
});
});
}
var requestObj = {
company1: [{
name: "Prod1",
qty: "12"
}, {
name: "Prod2",
qty: "10"
}],
company2: [{
name: "Prod3",
qty: "11"
}, {
name: "Prod4",
qty: "13"
}],
company3: [{
name: "Prod5",
qty: "1"
}, {
name: "Prod6",
qty: "2"
}, {
name: "Prod7",
qty: "3"
}]
}
for(let companyName in requestObj){
let orderData = requestObj[companyName];
placeOrder(orderData);
}

How to deserialize specific properties from JSON response using NewtonSoft Json library

Here's my JSON
{
"userReviewList": [{
"userReviewId": "789021517",
"body": "My shopping experience has bla bla bla",
"date": "Apr 16, 2013",
"name": "Djdannybhhhhh",
"rating": 5,
"title": "Awesome!",
"voteCount": 0,
"voteSum": 0,
"viewUsersUserReviewsUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"voteUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"reportConcernUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"reportConcernExplanation": "xxxxxxxxxxxxxxxxxxxxxxxxxx.",
"customerType": "Customers",
"reportConcernReasons": [{
"reasonId": "0",
"name": "Choose One"
}, {
"reasonId": "1",
"name": "This review contains offensive material"
}, {
"reasonId": "8",
"name": "This review is not a review or is off-topic"
}, {
"reasonId": "9",
"name": "I disagree with this review."
}, {
"reasonId": "7",
"name": "My concern isn't listed here."
}
]
}, {
"userReviewId": "780537396",
"body": "xxxxxxxxxxxxxxxxxxxxxx",
"date": "Apr 2, 2013",
"name": "Majak6",
"rating": 5,
"title": "Smart!",
"voteCount": 0,
"voteSum": 0,
"viewUsersUserReviewsUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"voteUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"reportConcernUrl": "https://xxxxxx.com/us/rexxxws?usxxxxileId=xxxxxx",
"reportConcernExplanation": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"customerType": "Customers",
"reportConcernReasons": [{
"reasonId": "0",
"name": "Choose One"
}, {
"reasonId": "1",
"name": "This review contains offensive material"
}, {
"reasonId": "8",
"name": "This review is not a review or is off-topic"
}, {
"reasonId": "9",
"name": "I disagree with this review."
}, {
"reasonId": "7",
"name": "My concern isn't listed here."
}
]
}
]
}
I don't want to create separate class using json2csharp as I have already one class with specific properties I want to deserialize json to that class. That class has 'body', 'date', 'title', 'votecount' property (which are in json) & also some other properties are also in there, which are not in JSON. How can I do that in my Windows Store App using Newtonsoft Json library.

Parse Json with different type of inner array

I have a great problem for parse a very difficult json string. For Eg
{
"facilityDetails": [
{
"tableName": "FACILITY",
"facilityDetails": [
{
"id": 1,
"itemId": "s101",
"name": "facility",
"status": 1,
"lastEditedOn": "01/Jan/201200: 00: 00.000"
}
]
},
{
"tableName": "PLACE_SERVICE",
"facilityDetails": [
{
"id": 1,
"itemId": "22",
"name": "placeservice",
"facility": "5",
"status": 1,
"lastEditedOn": "01/Jan/201000: 00: 00.000"
},
{
"id": 2,
"itemId": "55",
"name": "placeservice",
"facility": "t",
"status": 2,
"lastEditedOn": "01/Jan/201000: 00: 00.000"
},
{
"id": 3,
"itemId": "99",
"name": "placeservice",
"facility": "r",
"status": 33,
"lastEditedOn": "01/Jan/201000: 00: 00.000"
},
{
"id": 4,
"itemId": "22",
"name": "placeservice",
"facility": "",
"status": 0,
"lastEditedOn": "01/Jan/201000: 00: 00.000"
}
]
},
{
"tableName": "AGENT",
"facilityDetails": [
{
"agentId": 2,
"itemId": "1",
"name": "agent",
"defUnitId": 0,
"defRouteId": 0,
"color": "",
"synonyms": "",
"administrationType": 0,
"status": 0,
"lastEditedOn": "01/Jan/201200: 00: 00.000"
}
]
}
]
}
for this json string "facilityDetails" is an inner array that have different details at each time. How can i parse this type of json. If anyone know please help me
You should be able to parse this with the Json.NET library.
http://james.newtonking.com/projects/json-net.aspx