react native geocoding get address - react-native

I need help for this kind of error when running this will happen object [] , []
Geocoder.getFromLatLng(28.6139,77.2090).then(
json => {
var addressComponent = json.results[0].address_components[0];
alert(addressComponent);
}, error => {
alert(error+"CATCH");
} )

It looks like you are trying to alert an object doing so usually results in getting the following response:
[object Object]
Which isn't really useful. You can solve this by using JSON.stringify
alert(JSON.stringify(addressComponent)) or alert(JSON.stringify(error))
Doing a reverse geocode lookup on the coordinates gives the following alert when I use JSON.stringify
You can read more about JSON.stringify here in the docs.
The JSON.stringify() method converts a JavaScript object or value to a JSON string
While using alert is useful, I prefer using console.warn as you would get something like this, which means you don't have to stringify every response

Related

vTiger webservice update operation

im trying to do an update operation from angular 2 but i dont know how to pass the element parameter
in the vtigercrm.log i see DEBUG webservice -
array ('element' => NULL)
which leads to this
"error": {
"code": "ACCESS_DENIED",
"message": "Permission to perform the operation is denied for id",
i tryied passing the following object as a JSON
{
"subject":"test2",
"assigned_user_id":"19x1",
"date_start":"2016-11-15",
"time_start":"12:00:00",
"due_date":"2016-11-15",
"time_end":"14:00:00",
"recurringtype":"",
"duration_hours":"2",
"duration_minutes":"0",
"parent_id":"",
"eventstatus":"Planned",
"sendnotification":"0",
"activitytype":"Call",
"location":"",
"createdtime":"2016-11-15 11:31:19",
"modifiedtime":"2016-11-15 11:31:19",
"taskpriority":"",
"notime":"0",
"visibility":"Public",
"modifiedby":"19x1",
"description":"",
"reminder_time":"",
"contact_id":"",
"latitud":"",
"longitud":"",
"id":"18x22029"
}
the same thing as encodeURI and encodeURIComponent but nothing works
I had a similar error, and I found a subtle difference in the JSON. When a result was returned, the json object is the first element in an array. But for sending, it needs to be just the object, not an array.
<?php
//decode the json encode response from the server.
$jsonResponse = json_decode( $response->getBody(), true );
//Get first array element for sending back with update
$objectJson = json_encode($jsonResponse[ 'result' ][0]);
?>
Whenever I tried sending the original response, I received an error: {"success":false,"error":{"code":"ACCESS_DENIED","message":"Permission to perform the operation is denied for id"}}
This error message can be due to:
Object ID not mentionned/correct in the JSON objet that you send as the parameter "element"
Vtiger Session ID not sent/correct in the parameter "sessionName"
See here an example (in PHP) of how to pass the object to perform an update

Assertion Failed: Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array

I have just got this error a few days ago. Whenever I try to run
this.store.queryRecord('user', {filter:{username : params.username}});
It shows error: Assertion Failed: Expected the primary data returned by the serializer for a queryRecord response to be a single object but instead it was an array.
What is the problem here?
You backend should return one object not array.
Found a way to avoid this problem. Instead of queryRecord ( which seems to be changed by ember-data developer team ), I use store.query like this:
this.store.query('user', {filter:{username : params.username}}).then(function(user){return user.get('firstObject')});
I encountered similar situation , had 2 routes
this.get('/clients', function() {return {data: [allClientsDataJson]};});
this.get('/clients:id', function() {return {data: [oneClientDataJson]};});
But after using queryRecord i got same error. Thing was that second route was never called and first one was called in both causes. So instead of single result there was array with all results in second call.
After knowing only first one is always called i edited it to :
this.get('/clients', function(db, request) {
if(!Ember.isEmpty(request.queryParams)) { return oneClientDataJson
} else { return allClientsDataJson }

How to get an object from a _ref

I apologize if this is a stupid/newb question, but when a Rally query result is returned with a _ref (using the Javascript SDK 1.32), is there a way to directly get the object associated with the _ref?
I see that I can use getRefFromTypeAndObjectId to get the type and the object ID, and then query on that type and object ID to get the object, however I wondered if there was something like getObjectFromRef or some other such way to more directly get back the object associated with the reference.
Excellent question. The getRallyObject method on RallyDataSource should do what you need.
var ref = '/defect/12345.js';
rallyDataSource.getRallyObject(ref, function(result) {
//got it
var name = result.Name;
}, function(response) {
//oh noes... errors
var errors = response.Errors;
});
In SDK 2.0 you use the load method of a data model to read a specific object. Check out this example: http://developer.help.rallydev.com/apps/2.0p5/doc/#!/guide/appsdk_20_data_models

JSON result problems in ASP.NET Web API when returning value types?

I'm learning aspnet mvc 4 web api, and find it very easy to implement by simply returning the object in the apicontrollers.
However, when I try to return value types such as bool, int, string - it does not return in JSON format at all. (in Fiddler it showed 'true/false' result in raw and webview but no content in JSON at all.
Anyone can help me on this?
Thanks.
Some sample code for the TestApiController:
public bool IsAuthenticated(string username)
{
return false;
}
Some sample code for the jQuery usage:
function isAuthenticated(string username){
$.getJSON(OEliteAPIs.ApiUrl + "/api/membership/isauthenticated?username="+username,
function (data) {
alert(data);
if (data)
return true;
else
return false;
});
}
NOTE: the jquery above returns nothing because EMPTY content was returned - however if you check it in fiddler you can actually see "false" being returned in the webview.
cheers.
Before your callback function is called, the return data is passed to the jquery parseJSON method, which expects the data to be in the JSON format. jQuery will ignore the response data and return null if the response is not formatted correctly. You have two options, wrap you return boolean in a class or anonymous type so that web api will return a JSON object:
return new { isAuthentication = result }
or don't use getJSON from jQuery since you're not returning a properly formatted JSON response. Maybe just use $.get instead.
Below is a quote for the jQuery documentation:
Important: As of jQuery 1.4, if the JSON file contains a syntax error,
the request will usually fail silently. Avoid frequent hand-editing of
JSON data for this reason. JSON is a data-interchange format with
syntax rules that are stricter than those of JavaScript's object
literal notation. For example, all strings represented in JSON,
whether they are properties or values, must be enclosed in
double-quotes. For details on the JSON format, see http://json.org/.

Does a foreach loop work directly with a JSonStore data object store?

I create a JSonStore with a JSON formatted array of objects.
I have verified it is properly formatted.
I then try to use a dojo forEach loop on it but the JSonStore doesn't seem to have any data in it. I can specify the target in my web page URL and it shows the right data. But using console.log(myJsonStore) shows an object but I don't see the data in Firebug. I also don't see any GET for the service providing the data. It's like specifying the target path in a URL in the browser fires the GET but not when I try to trigger it in the postCreate where my foreach is located.
The answer from Ricardo, i believe is a little incorrect, seeing as the JsonRest.query function returns a dojo.Deferred.
You have a REST call being made asynchroniously through store read api - and once it returns values, it will promise to run whats set as the callback.
Try this for your loop iterator instead
storeObj.query( {} ).then(function ( results ) {
dojo.forEach( results, function( obj ) {
console.log( obj );
});
}
you can do this:
var storeObj = new JsonRest({
target: "/some/resource"
});
storeObj.query({}).forEach(function(obj){console.log(obj);});
that should do the trick