Please give me an Idea how to use map() for below json and how to create dynamic form for this json.
I m not getting how to use this json for create dynamic from in react-native
{
"Location": {
"field_count": 1,
"field_name": [
"location"
],
"field_type": "TextField",
"context_type": "Location",
"field_unit": null,
"is_compulsory": true
},
"Maximum Tie Bar": {
"field_count": 2,
"field_name": [
"max_tie_bar_1",
"max_tie_bar_2"
],
"field_type": "TextField",
"context_type": "Decimal",
"field_unit": "mm x mm",
"is_compulsory": true
},
"Type": {
"field_count": 1,
"field_name": [
"type"
],
"field_type": "Dropdown",
"field_values": [
"Injection Mold",
"Gas Injection Mold",
"PVC Mold",
"Overmold/Insert Mold",
"Transfer Mold",
"Compression Mold",
"2k Mold",
"Stack Mold"
],
"is_compulsory": true
}
}
You can do it like this:
First Loop over your JSON object
Object.keys(JSON_OBJECT).map(function(item) {
renderItemsFromJson(JSON_OBJECT[item])
});
Conditionally render your items accordingly
renderItemsFromJson = (item) => {
switch(item.field_type){
case 'TextField':
return '<TextInput>[Inside code]</TextInput>'
case 'Dropdown':
return '<YourDropDownComponent>[Insidecode]</YourDropDownComponent>'
//Likewise
}
}
Related
I don't know how to remove the nested array in react native. Example :
Array [
Array [
Array [
"77",
undefined,
"Double Pixel Chart",
"c1",
"Chart",
],
Array [
"78",
undefined,
"Heikin Ashi Chart",
"c2",
"Chart",
],
],
]
What I want is just this array structure :
Array [
"77",
undefined,
"Double Pixel Chart",
"c1",
"Chart",
],
Array [
"78",
undefined,
"Heikin Ashi Chart",
"c2",
"Chart",
],
This is my code for pushing into the array :
for (let menu of response.data.Data) {
apiChartingMenu = new ApiChartingMenuModel (
menu.idx,
menu.shortDescription,
menu.titlecommand,
menu.command,
menu.commandtype,
);
data.push(Object.values(apiChartingMenu));
}
How can I achieve this?
You can use plain Javascript by using array.flat(). For your case this could be done as follows.
array = [
[
[
"77",
undefined,
"Double Pixel Chart",
"c1",
"Chart",
],
[
"78",
undefined,
"Heikin Ashi Chart",
"c2",
"Chart",
],
]
]
console.log(array.flat())
In your case you could make it work by either using
data.push(Object.values(apiChartingMenu).flat());
or by not introducing the object ApiChartingMenuModel at all, since you are just using its values anyway. This could also be done as follows.
// dummy menu object
menu = {
idx: 77,
shortDescription: "description",
titlecommand: undefined,
command: undefined,
commandtype: undefined
}
data = []
data.push([menu.idx, menu.shortDescription, menu.titlecommand, menu.command, menu.commandtype])
console.log(data)
I have the signature of a Solana transaction and I want to find the wallet ID of the sender and the receiver. This is what I did:
const connection = new Web3.Connection(Web3.clusterApiUrl("devnet"), "confirmed");
const transaction = await connection.getTransaction(signature);
When I do console.log(transaction), it has fields like blockTime and all, but not to and from address. Can someone help?
When calling getTransaction, the node will return the transaction in the format specified. By default, connection.getTransaction will return the transaction with base58 encoding, so try using connection.getParsedTransaction instead. Here's an example for a simple transfer:
curl https://api.devnet.solana.com -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getTransaction",
"params": [
"2YHDUWRRh4jwaAqSPJqCiu97FTy6Pu2C6XGbAzsaBbyjQeXW11z
hhF3DJHt4vDFHVND1ybdSHf6E5FxbjFXZP4gQ",
"jsonParsed"
]
}
' | python3 -m json.tool
{
"jsonrpc": "2.0",
"result": {
"blockTime": 1647001173,
"meta": {
"err": null,
"fee": 5000,
"innerInstructions": [],
"logMessages": [
"Program 11111111111111111111111111111111 invoke [1]",
"Program 11111111111111111111111111111111 success"
],
"postBalances": [
23932341357,
110000000,
1
],
"postTokenBalances": [],
"preBalances": [
23942346357,
100000000,
1
],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
},
"slot": 120237987,
"transaction": {
"message": {
"accountKeys": [
{
"pubkey": "4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn",
"signer": true,
"writable": true
},
{
"pubkey": "4AUt2JyjzJYVhWkjKugXmzhWizpb4SpLHBtL2fuqPskU",
"signer": false,
"writable": true
},
{
"pubkey": "11111111111111111111111111111111",
"signer": false,
"writable": false
}
],
"instructions": [
{
"parsed": {
"info": {
"destination": "4AUt2JyjzJYVhWkjKugXmzhWizpb4SpLHBtL2fuqPskU",
"lamports": 10000000,
"source": "4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn"
},
"type": "transfer"
},
"program": "system",
"programId": "11111111111111111111111111111111"
}
],
"recentBlockhash": "3zny2xt5wimev9Jry3TiAyK8yA2pMMcGvsPWpFN5HiL6"
},
"signatures": [
"2YHDUWRRh4jwaAqSPJqCiu97FTy6Pu2C6XGbAzsaBbyjQeXW11zhhF3DJHt4vDFHVND1ybdSHf6E5FxbjFXZP4gQ"
]
}
},
"id": 1
}
In result.transaction.message.instructions[0].parsed you'll get what you're looking for.
More information about the getTransaction call at https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
I'm trying to write a node.js script to create a set of Facebook audiences based on URL structure, but I'm getting the below error and I can't seem to identify what is wrong with the JSON I'm sending:
Error I'm getting back: FacebookRequestError: Invalid rule JSON format: Invalid rule JSON format.
It seems that the 'rule' property of the 'params' object is somehow invalid, but I can't identify what is wrong with it. I even tried copying their example from the docs and it gave the same error. I also pasted the JSON into the API explorer and the editor there indicated valid JSON, but the API response was the same.
api explorer screenshot
After reading this similar question, I tried a bunch of variations using single vs double-quotes, JSON.stringifying the whole thing, part of it, none of it, etc... I'm hoping fresh eyes might catch it.
My Code:
"use strict";
const bizSdk = require("facebook-nodejs-business-sdk");
const AdAccount = bizSdk.AdAccount;
const CustomAudience = bizSdk.CustomAudience;
const access_token = "REDACTED";
const app_secret = "REDACTED";
const app_id = "REDACTED";
const id = "act_REDACTED";
const pixelID = "REDACTED";
const api = bizSdk.FacebookAdsApi.init(access_token);
const showDebugingInfo = true; // Setting this to true shows more debugging info.
if (showDebugingInfo) {
api.setDebug(true);
}
const logApiCallResult = (apiCallName, data) => {
console.log(apiCallName);
if (showDebugingInfo) {
console.log("Data:" + JSON.stringify(data));
}
};
let fields, params;
fields = [
];
params = {
"name": "Website - Viewed Product - Corrugated Containers - 180 days",
"rule": {
"inclusions": {
"operator": "or",
"rules": {
"inclusions": {
"operator": "or",
"rules": [
{
"event_sources": [
{
"id": pixelID,
"type": "pixel"
}
],
"retention_seconds": 8400,
"filter": {
"operator": "and",
"filters": [
{
"field": "url",
"operator": "i_contains",
"value": "/products/corrugated-containers"
}
]
}
}
]
}
}
}
},
"retention_days": "180",
"prefill": "1"
};
const customaudiences = (new AdAccount(id)).createCustomAudience(
fields,
params
);
logApiCallResult("customaudiences api call complete.", customaudiences);
It looks like I had accidentally nested a rules object within a rules object somehow! I fixed that and it created the audience without throwing an error...now I can't see the audience definition in Facebook's interface to check that it's correct, but that's a completely different topic.
I changed...
params = {
"name": "Website - Viewed Product - Corrugated Containers - 180 days",
"rule": {
"inclusions": {
"operator": "or",
"rules": {
"inclusions": {
"operator": "or",
"rules": [
{
"event_sources": [
{
"id": pixelID,
"type": "pixel"
}
],
"retention_seconds": 8400,
"filter": {
"operator": "and",
"filters": [
{
"field": "url",
"operator": "i_contains",
"value": "/products/corrugated-containers"
}
]
}
}
]
}
}
}
},
"retention_days": "180",
"prefill": "1"
};
to
params = {
"name": "Website - Viewed Product - Corrugated Containers - 180 days",
"rule": {
'inclusions': {
'operator': 'or',
'rules': [{
'event_sources': [{
'id': pixelID,
'type': 'pixel'
}],
'retention_seconds': retention_seconds,
'filter': {
'operator': 'and',
'filters': [{
'field': 'url',
'operator': 'i_contains',
'value': '/products/corrugated-containers'
}]
}
}]
}
},
"retention_days": retention_days,
"prefill": "1"
};
I am trying to upload my intent everything is working fine, i am writing script in V2 and everything works but for parameter webhookState data type is enum ( [here] ) and we have to enter following of the three values ( [here][1]) now when i enter any one and try to upload it shows.
" Unable to load file: SyntaxError: Unexpected token W in JSON at position 98 "
now when I pass WEBHOOK_STATE_ENABLED(or any one) in quotes code uploads successfully (because as per my knowledge it treats it as string and gets executed) and intent is created for my agent but webhook remains off and also training phrases are not there, i am certain that the parameter webhookState is not being activated when i pass in quotes(because of above mentioned reason) Same is the case with rest, like when i try to put in type of training phrases.
{
"name": "Warehouse_Management",
"displayName": "Warehouse_Management",
"webhookState": "WEBHOOK_STATE_ENABLED_FOR_SLOT_FILLING" ,
"priority": 50000,
"isFallback": false,
"mlDisabled": false,
"trainingPhrases": [
{
"name":"Try1" ,
"type": "EXAMPLE",
"parts": [
{
"text": "for",
"userDefined": true
},
{
"text": "warehouse",
"entityType": "#Properties",
"alias": "Properties",
"userDefined": true
},
{
"text": "management",
"userDefined": true
}
]
},
{
"name":"Try2" ,
"type": "EXAMPLE",
"parts": [
{
"text": "i want app for ",
"userDefined": true
},
{
"text": "warehouse",
"alias": "Properties",
"entityType": "#Properties",
"userDefined": true
}
]
}
],
"outputContexts": [
{
"name": "Yes",
"lifespanCount": 2
},
{
"name": "No",
"lifespanCount": 2
},
{
"name": "Device_Integration",
"lifespanCount": 2
}
],
"resetContexts": false,
"parameters": [
{
"name": "Properties",
"displayName": "Properties",
"value": "$parameter_name",
"entityTypeDisplayName": "#Properties",
"mandatory": false,
"isList": true
}
],
"messages": [
{
"text":"This is sample response"
}
],
"rootFollowupIntentName": "root",
"parentFollowupIntentName": "parent"
}
Please NOTE that in the attached Json i have put it in quotes so it would get successfully executed and will create intent.
In order for it to be valid JSON, the enum value should be wrapped in quotes. It's expecting the enum value as a String.
I am trying to parse some json that my server replies me.
I am getting this answer from the server:
{
"ROWCOUNT": 1,
"COLUMNS": [
"REGISTRATION_DT",
"USERNAME",
"PASSWORD",
"FNAME",
"LNAME",
"EMAIL",
"MOBILE",
"FACEBOOK_ID"
],
"DATA": {
"REGISTRATION_DT": [
"March, 17 2012 16:18:00"
],
"USERNAME": [
"user"
],
"PASSWORD": [
pass
],
"FNAME": [
"name"
],
"LNAME": [
"lname"
],
"EMAIL": [
"somemail"
],
"MOBILE": [
mobile
],
"FACEBOOK_ID": [
"fbid"
]
}
}
I am trying to extract the data with this way:
var xml2 = this.responseData;
var xml3 = JSON.parse(xml2);
Ti.API.log(xml3.DATA[0].FNAME);
What I am doing wrong here?
You're reading your JSON wrong. DATA is an object of arrays and not vica versa.
Ti.API.log( xml3.DATA.FNAME[0] );
Ti.API.log(xml3.DATA.FNAME[0]);
Two fields come without quotes:
"PASSWORD": [
pass
]
And
"MOBILE": [
mobile
],
xml3.DATA is an object, not an array.
You need to write
xml3.DATA.FNAME[0]