Passing values from resource file to list picker in wp8 - windows-phone-8

I have array collectoon of 200 items,I given keys and values in resource files and kept the keys in an array .I want to pass this array to list picker
In this manner:
String[] countries={"In","Aus","Bng","pak",..............};
for(int i=0;i<countries.length;i++ )
{
//I need to add in this manner but resources have only static strings
countrieslistpicker.Items.Add(Resources.countries[i])
}
so how can i dynamically get from resorce files .

You can use the Resource Manager's GetString() Method to access items in the resource files.

Try following approach
for(int i=0;i<countries.length;i++ )
{
var countryName = AppResources.ResourceManager.GetString(Resources.countries[i])
countrieslistpicker.Items.Add(countryName);
}

Related

How to get a data from JSON in React Native?

When I run the below code in my react-native project
console.log("Response= "+JSON.stringify(response));
I can get output like below in my console.
Response= {"assets":[{"height":3888,"uri":"file:///data/user/0/com.facebook2/cache/rn_image_picker_lib_temp_6b8db334-4fcc-40ba-94a0-325191a89011.jpg","width":5184,"fileName":"rn_image_picker_lib_temp_6b8db334-4fcc-40ba-94a0-325191a89011.jpg","type":"image/jpeg","fileSize":1914937}]}
How I print the 'uri' from that JSON response ?
Looking at your data we can break it down by what we see. So, with JSON we have a Javascript Object which contains a param of assets. So to print assets we would console.log(response.assets)
Assets is an array with one item, so we want to get the first item from that which would be console.log(response.assets[0]).
Then we want the uri from that first assets object which would be console.log(response.assets[0].uri)
Hope this is what you are looking for.
You can use Dot Notation to access the properties of an object.
In your response json, it is seen that it has an array with name assets. The required property uri is inside the array. You can access it simply by
response.assets[0].uri
if there were multiple items in your assets array, you can simply loop over the array and get the values,
const length = response.assets.length;
for(let i=0; i< length; i++)
console.log('URI is = ', response.assets[i].uri)
const response = {"assets":[{"height":3888,"uri":"file:///data/user/0/com.facebook2/cache/rn_image_picker_lib_temp_6b8db334-4fcc-40ba-94a0-325191a89011.jpg","width":5184,"fileName":"rn_image_picker_lib_temp_6b8db334-4fcc-40ba-94a0-325191a89011.jpg","type":"image/jpeg","fileSize":1914937}]};
console.log('URI =', response.assets[0].uri)

Read a csv file that has a JSON column in SSIS?

I have the following CSV file that has 4 columns. The last column addresses holds 2 addresses history in a JSON format. I have tried to read it in SSIS but it splits the JSON along with the comma(,) instead of grouping all the addresses under one column.
I am using a flat-file connector for this. Is there any other source component for this type of content? How can I parse this in SSIS so that there are just 4 columns and the addresses appear all under one column?
id,title,name,addresses
J44011,Mr,James,"{""address_line_1"": 45, ""post_code"": ""XY7 10PG""},{""address_line_1"": 15, ""post_code"": ""AB7 1HG""}"
You can use a script component to process the JSON into its own detail table.
I created the following dataflow:
Here are the steps to the script component:
On inputs add ID and Address columns:
On inputs and outputs: add a new output and create columns (remember to program the datatypes:
The script:
public class Addresses
{
public int address_line_1 { get; set; }
public string post_code { get; set; }
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
//Test if addresses exist, if not leave the Row processing
if (string.IsNullOrEmpty(Row.addresses)) return;
//Fix Json to make it an array of objects
string json = string.Format("[{0}]", Row.addresses);
//Load into an array of Addressses
Addresses[] adds = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Addresses[]>(json);
//Process the array
foreach (var a in adds)
{
rowsAddressesBuffer.AddRow();
rowsAddressesBuffer.ID = Row.id;
rowsAddressesBuffer.Address1 = a.address_line_1;
rowsAddressesBuffer.PostalCode = a.post_code;
}
}
Notes:
The class added to store results.
The JSON had to be fixed to create an array of objects.
You need to add a reference to System.Web.Extensions.
This goes to the load. Make sure text qualifier is defined as a double quote (")
I have tried to read it in SSIS but it splits the JSON along the comma(,) instead of grouping all the addresses under one column.
In order to force SSIS to read the flat file row in 4 columns, you should open the flat file connection manager, go to Advanced Tab, and Add only 4 columns. Make sure the last column length is equal to 4000. This will force reading the 4th column without splitting it.
After importing data to SQL Server, you can parse the JSON content using OPENJSON() function
Parse and Transform JSON Data with OPENJSON (SQL Server)

Dart How To parse JSON With Unique Key, Value Pairs

I am parsing a JSON object containing several key value pairs but am not sure how to make objects out of the JSON below. The keys are always different depending on the GET request so I am not able to use json['keyname'] like usual. What kind of function would I need in order to return a list of keys from 'ccwms' and a respective list of values (floats)?
{
"ccwms": {
"frc118": 160.8076758518209,
"frc1255": 15.257951313413884,
"frc1296": 11.42077882954301,
"frc7321": -161.58464745359254
}
}
After parsing the JSON, you have a normal Dart Map with string keys and some values. You can iterate maps in several ways, for example:
for (var key in map.keys) { doSomething(key, map[key]); }
for (var entry in map.entries) { doSomething(entry.key, entry.value); }
map.forEach(doSomething);
(Map.keys, Map.entries, Map.forEach).
I'm sure there are more ways to access all the keys and values.
What you do with the keys and values is up to you, it's just a map.
Minimal Dart program to convert a json string:
import 'dart:convert';
main() {
String source = """{"X":"RRRR","Y":"SSSS","ccwms": {
"frc118": 160.8076758518209,
"frc1255": 15.257951313413884,
"frc1296": 11.42077882954301,
"frc7321": -161.58464745359254
}}""";
dynamic target = JsonDecoder().convert(source);
print ( source.toString());
}
Are these keys random ? I think keys have to be predefined set, because json is a serialization for already existed object and the object structure can not be random
hope I understand correctly
should be a comment but I can not add comments right now.

How do I parse this JSON data and get the attributes I want as a list?

I am building an air app that needs to access data from Firebase Database using the REST API. I am able to get the data but I do not know how to get the information I need from that data.
Basically, I have an Android app and a Desktop app. The android app uploads/Modifies data and the Desktop app needs to access that data and send signals to the ESP8266 via a socket connection. I have a list of 'Lights' each light as a 'lightname', 'status' and 'pin'. I want to be able to loop through all the 'pin's.
When I try to get the data , I get this JSON:
{"-LAb_YKS9l7qQno25AY5":{"lightname":"light1","pin":"14","status":"on","timestamp":1524303808146},"-LAb_cRpsGpQfr7JbCfI":{"lightname":"light2","pin":"15","status":"on","timestamp":1524303830159},"-LAb_zbf2sYuyTtW_uEr":{"lightname":"blah","pin":"9","status":"on","timestamp":1524303921921},"-LAba68lzyG15n6anuSF":{"lightname":"dishl","pin":"7","status":"on","timestamp":1524303955946},"-LAdZW2JjQVGfLMc_sb4":{"lightname":"cxcxc","pin":"14","status":"on","timestamp":1524337092712}}
I want to loop through all the lights and access their 'pin' values.
Here is what i've tried:
for (var i:int = 0; i < e.target.data.length; i++)
{
trace(e.target.data[i]["status"]);
}
I get this error:
Property 0 not found on String and there is no default value.
Any help is greatly appreciated.
Because the e.target.data answer you get from Firebase is a String and first you need to JSON.parse(...) it to transform it into data. Then your data is not an Array, it is an Object. You loop through it as following:
// Parse the incoming data.
var aData:Object = JSON.parse(e.target.data);
// Loop through string keys of the data object.
for (var aKey:String in aData)
{
trace("");
trace(aKey);
// Assign entry reference to another local variable. This is not
// mandatory, but the following code is shorter and thus more readable.
var anEntry:Object = aData[aKey];
trace(anEntry['pin']);
trace(anEntry['status']);
trace(anEntry['lightname']);
}
If you have no use of key values, you might do it in a slightly different way:
// Parse the incoming data.
var aData:Object = JSON.parse(e.target.data);
// Loop through values of the data object while ignoring the keys.
for each (var anEntry:Object in aData)
{
trace("");
trace(anEntry['pin']);
trace(anEntry['status']);
trace(anEntry['lightname']);
}

Parsing JSON Data from URL with Android Studio

I'm trying to parse JSON data from URL and show the data in my app.
JSON Example (After accessing specific URL):
[{"placeID":"1","placeName":"Test Place","city":"New York","type":"Rest"..
How I can read this data and show a list of the places recieved from the API?
I've been trying ALL of the guides over the internet for parsing JSON data from URL with Android Studio and without. As a total beginner with Android developement, I couldn't make one working exmaple with json even when the author shared the final example for download. I hope you can help me in noob-friendly way and step by step or refer me to the right places.
Thank you!
I believe Android uses org.json as the JSON library, in which case something like this works to retrieve information about each place (assuming data is a valid JSON string)
try {
String data = "\"[{\"placeID\":\"1\",\"placeName\":\"Test Place\",\"city\":\"New York\",\"type\":\"Rest\"..";
JSONArray places = new JSONArray(data);
for (int i = 0; i < places.length(); i++)
JSONObject place = (JSONObject) places.get(i);
int id = place.getInt("id");
String name = place.getString("placeName");
String city = place.getString("city");
// etc...
// Do what you wish with the id, name, city and other variables.
// It loops through here for each item in the JSON variable.
}
} catch (JSONException e) {
e.printStackTrace();
}
This goes through each place in the JSON array and grabs some of the variables from it. It would probably be smart to create a data class and call it something like Place. You could then pass in the data with a constructor: new Place(id, name, city); (see this constructor for example: https://stackoverflow.com/a/22419370/5236779).