Json to List view Conversion retriving null values in xmarian.forms cross platform - xamarin.forms.listview

Am trying to convert JSON data to list but its showing null. my code and JSON data like below.But in the list (lst) it showing null.
JSON:
{"Data":[{"LocationId":6,"LocationName":"abc","ServiceUrl":"www.google.com", },{"LocationId":3,"LocationName":"abcd","ServiceUrl":"192.168.0.110/IKLT/service.svc"}],"ErrorCode":"201 - Success","Message":"Success","Status":true}
Code:
GetLocationResult lst= JsonConvert.DeserializeObject<GetLocationResult>(result);
GetLocationResult lr = (GetLocationResult)JsonConvert.DeserializeObject(result, typeof(GetLocationResult));
GetLocationResult is a class for above JSON

I inspected your json string, the syntax is wrong. Remove the extra comma shown in the picture below:

Related

how get all id from json to array on other variables - jmeter

I have two JSON. In the both I have name. How can I get names from first JSON and add to array? Later I want do this same with second JSON later i want both array compare? How can I do this?
jsonArray1 = [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}];
jsonArray2 = [{'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}];
for example I want:
a = [doug, dofug] b = [goud, doaaug]
and later check if these are the same arrays
i don't know how can i do this in jmeter, help
To convert one array to another:
Add JSR223 PostProcessor as a child of the request which returns first JSON Array
Put the following code into "Script" area:
def builder = new groovy.json.JsonBuilder()
builder(com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(),'$..name').collect())
vars.put('array1', builder.toPrettyString())
That's it, you should be able to access the newly generated JSON Array as ${array1} where required
Repeat the same steps for the second JSON array.
There are several options on how to compare 2 JSON entities, depending on what you're trying to achieve you can go for:
Response Assertion
a JSR223 Assertion and a 3rd-party library like:
Jackson
Gson
JSONassert

Parameterize() must be of the type array, string given in Laravel 5.2

i am using laravel 5.2 and trying to update records using whereIn('id',[1,2]) but when i try to pass a json value [1,2] to it , i returns
parameterize() must be of the type array, string given. I am mentioning my code below.
$load_id=json_encode($request->chk_load,JSON_NUMERIC_CHECK); // it returns [1,2]
Load::whereIn('id',$load_id)->update(array('status'=>3));
What should i do to fix this error. ?
seems json_encode($request->chk_load,JSON_NUMERIC_CHECK);
returns json string and not an array..
can you elaboarate $request->chk_load is what kind of data it is?

Load JSON data containing arrays in PIG

I have JSON file of the format:
{"id": "59b6808364fdb09cde10ad3b","balance": "$1,972.02","age": 35,"eyeColor": "green","tags": ["aute","nostrud","pariatur","adipisicing","irure"]}
{"id": "59b6808334cd60be95e5c166","balance": "$3,697.85","age": 32,"eyeColor": "blue","tags": ["tempor","non","ad","adipisicing","ut"]}
{"id": "59b680834544a828191abc88","balance": "$1,102.43","age": 38,"eyeColor": "brown","tags": ["quis","non","ut","veniam","ipsum"]}
I need to load this data into pig. I am using:
raw_data = LOAD '/path/to/file' USING JsonLoader('id:chararray, balance:chararray, age:int, eyeColor:chararray, tags:chararray')
I am not getting correct result using this when using dump raw_data;
What is the correct data type to load arrays in Apache PIG?
There is another question which mentions how to expand an array but for my case I can have variable elements in tags element.
Even if I could covert the array to string and then load it that would be fine.
Enclose the field inside tags with {}
raw_data = LOAD '/path/to/file' USING JsonLoader('id:chararray, balance:chararray, age:int, eyeColor:chararray, tags:{items:chararray}')

Getting rates from an array - json

I am trying to get the rates from this website.
So I connect with website = Faraday.get('https://bitpay.com/api/rates')).status == 200 and then try to parse this.
A segment of the response I get is:
#<Faraday::Response:0x007fcf1ce25688
#env=
#<struct Faraday::Env
method=:get,
body=
"[{\"code\":\"BTC\",\"name\":\"Bitcoin\",\"rate\":1}, {\"code\":\"USD\",\"name\":\"US Dollar\",\"rate\":586.66},{\"code\":\"EUR\",\"name\":\"Eurozone Euro\",\"rate\":528.991322},{\"code\":\"GBP\",\"name\":\"Pound Sterling\",\"rate\":449.441986},{\"code\":\"JPY\",\"name\":\"Japanese Yen\",\"rate\":59907.95922},{\"code\":\"CAD\",\"name\"
When I do a website.body I get a String class of all these values found on that website. I want to parse them though (JSON?) so that I can get each rate as a float.
I tried something JSON.parse(website.body)["GBP"]["rate"].to_f but yet again it cannot work in a string.
The return I get is TypeError: no implicit conversion of String into Integer
I was having a similar (but not the same) format from a different rates website and this is how I was handling it. Do I need to change its format first or is there a different way around it?
You're trying to access to the parsed JSON with the key "GBP" but you have an array. It's like if you did
a = [1,2,3,4,5]
a['foo']
Try out
currencies = JSON.parse(website.body)
currencies.each { |currency| puts currency['rate'] }
and change it like you need

How to order the JSON values in Servlet?

I am a new guy for JSON, I don't know to send JSON object and Array...
But, I pass the JSON values like the below format,
object.put("code", "1");
object.put("message", "Success");
object.put("Name", "xxx");
object.put("F_Name","yyy");
object.put("Address", "zzz");
object.put("Phone_No","123");
out.println(object);
But it display like
{"Phone_No":"123","message":"Success","Address":"zzz","Name":"xxx","F_Name":"yyy","code":"1"}
I don't know, why it's display like this. How to order this? Please help me.
And this is what format, Array format or object format...
And tell how to send array values in JSON..
Thanks in advance..
You didn't write what is the class of the object. However, if you care about the order, use GSON and its JsonObject class:
import com.google.gson.Gson;
import com.google.gson.JsonObject;
JsonObject object = new JsonObject();
object.addProperty("code", "1");
object.addProperty("message", "success");
object.addProperty("Name", "xxx");
// ...
Gson gson = new Gson();
out.println(gson.toJson(object));
As my understanding of question and the code above, The "object" you already using might be json object. Usually JSON object can maintain data in the form of key, value pairs. So you are putting content into json object and displaying. That's why its getting displayed like that. The displayed format is json format. If you want to put array into json object you can put as you already did for normal strings.
object.put("array1", arrayvariable1[]);
object.put("array2", arrayvariable2[]);
I guess it might have helped you.

Resources