w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I convert a multi dimensional JSON object into javascript array
It is an array: var json = '[{"tabname":"orders","datagroups":[{"dataname":"ordersToday","datavalue":9},{"dataname":"orders30Days","datavalue":126}]}]'; var obj = $.parseJSON(json); Array.isArray(obj) // => true

Categories : Javascript

AngularJS: textarea bind to JSON object shows "object-object"
You can do that in two steps : Create a filter that'll stringify JSON (http://docs.angularjs.org/guide/dev_guide.templates.filters.creating_filters) $scope.watch the field to save it when it changes (example http://jsfiddle.net/ceJ4w/)

Categories : Angularjs

How to I create a multi-dimensional random shuffle sorter with textboxes by object name, or data inside object
Either make the value you are shuffling a struct or a class with the three properties, or make a compound control with the three text boxes on and shuffle them, Use index in ValuesToShuffle to calculate Y coordinate. Would be two ways.

Categories : Dotnet

Error: Object reference not set to an instance of an object./The connection was not closed. The connection's current state is open
For the first error, your executeScalar() call is returning a null value. Either refine your query - you can check your query by running it directly in your database - or change your logic to deal with null values. For the second error, if calling Open() is throwing that error, it's because the connection object was in use before and was not closed properly. It's usually considered bad practice to reuse connections like that, so consider creating a new connection instance when you go opening one. Edit: I tried to imply something in the second paragraph there, but now I feel I must make it explicit: don't forget to deal with the connection you left open there, as it may be a major performance hog for your application. Specially since it's an ASP.NET one. Dispose of connections as soon as

Categories : C#

how to make json object from an element in json object with unique values in underscore js
var col = [ { "MerchantName": "Fashion and You", "BrandList": " Nike, Fila", "MerchantImage": "Fashion-You-medium.jpeg" }, { "MerchantName": "Fashion and You", "BrandList": " Levis, Fasttrack, Fila", "MerchantImage": "Fashion-You-medium.jpeg" }, { "MerchantName": "ebay", "BrandList": "Nokia,HTC,Samsung", "MerchantImage": "ebay.jpeg" }, { "MerchantName": "amazon", "BrandList": "Apple,Dell,Samsung", "MerchantImage": "amazon.jpeg" }, { "MerchantName": "amazon", "BrandList": " pepe jeans, peter england, red tape", "MerchantImage, Fila": "amazon.jpeg" } ]; var brands = []; //get unique brands _.each(col, function(i){ brands = _.union

Categories : Javascript

In jquery each Loop from json object How (make loop find a value from object and compare to another object value to not repeat a print)?
Try var songs = {}; $.each(data, function(key,val) { if(val.Artist != ""){ var key = val.Artist + '@' + val.Album; if(!songs[key]){ output += '<li><a class="songname" href="#" data-src="'+ val.Location +'">' + val.Artist + '</a></li>'; songs[key] = true ; }//End of PreSong != Song }//End of val.Artist });//End of Each output += '</ol>'; $("#wrapper").append(output); Demo: Fiddle You can change the key to find the unique combination. Ex: if you want a unique combination of Artist, Album and Song then use var key = val.Artist + '@' + val.Album + val.Song;

Categories : Javascript

Create a empty JSON object from an existing JSON object array
You can use an object literal to store whatever you want. It is just a bag of properties (i.e. name) and values. e.g. var order = {}; Then an array literal could be used to hold the orders. e.g var orders = []; orders.push(order); But it would be just as easy to use another object literal with the id as a property. But it seems like you want some sort of validation. Perhaps something to manage the order data and handle the validation, etc. Like so: orderManager.dataStore = { _data: {}, //_redundantData = []; //could easily store in an array if id isn't unique get: function (id) { return this._data[id]; }, getAll: function () { return this._data; }, set: function (id, order) { validateOrder(order); this._data[id] = order; }, clear: function (id)

Categories : Javascript

Order JSON object alphabetical and return to JSON object
write a compare function function compare(a,b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; return 0; } then sort your data var cities = {}; $.getJSON('http://mypage.com/json/cities.php', function(data){ data.sort(compare); $.each(data, function (k, vali) { cities[vali.cid] = vali.name; }); });

Categories : Jquery

Getting [object Object] error when call JQuery Ajax function for Json data
The reason you are seeing that is that data.d is an object representing the returned JSON text response. When you pass in an object into alert, it displays [object Object]. Whatever you are looking for will be a property of data.d. I would put a breakpoint on that line and see what properties are available. It'll be something like data.d.myProperty which will contain the actual string / HTML you are trying to work with.

Categories : Asp Net

How to iterate a multidimensional json_decoded object in Perl to create a new json object?
Well, you aren't really going wrong; it is just the JSON format that is being as stupid as possible. The JSON is a hash of keys (which are sorted, numeric strings) which map to another level of hashes, which have the keys name and value: { "0": {"name": "someKey", "value": "someValue"}, "1": {"name": "anotherKey", "value": "anotherValue"} } (This data should probably be encoded as [{"someKey": "someValue"}, {"anotherKey": "anotherValue"}].) So what we'll do is to loop through the numerically sorted keys for the outer hash: for my $index (sort { $a <=> $b } keys %records) { ... } Inside that loop, we do not loop through the keys/values of the hash values. Instead, we just pick the values of the keys name and value: my $record_value = $records{$index}; my ($key, $value)

Categories : PHP

asp.net web api - action filter - cannot access posted json object from request object
As far as I understand your problem, you want to log requests in case there is a binding error. A binding error is somewhat exception so that you may handle exceptions of your controller or actions. To do this, you need to useExceptionFilterAttribute . The example below : public class ExceptionHandlingAttribute : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { string content = actionExecutedContext.Request.Content.ReadAsStringAsync().Result; ///LOGGING ACTIONS base.OnException(actionExecutedContext); } }

Categories : Asp Net Web Api

Ajax/jQuery/Json pass variable but I get [object Object] error
[object Object] means that $a, $b and $c are objects. To print out an object in javascript you should use data[index].variable where variable is the property of the object. Try to console.log(data) to see what you get: you should see 3 objects. Expand them, and read the variables inside of them. Also, since you're array is made of 3 elements, data[3] should not exists. You should post more PHP code.

Categories : PHP

how to loop through Json result object inside object array
I'd suggest that if your data is consistent, then you're better off working directly with the format and not looping through everything to find keys and values. I created a Fiddle using your code (skipping the AJAX part.) and for contrast another Fiddle with the following code: var success = function (data) { var product, i, len, $output = $('.resultJson'); for (i = 0, len = data.length; i < len; i++) { product = data[i]; console.log('Object: ' + i); var details = product.ProductDetails; var MSRP = product.ProductDetails.MSRP; var price = product.ProductDetails.Price; console.log(details); console.log(MSRP); console.log(price); $output.append("<br />"); $output.append("ProductId: " + product

Categories : Javascript

Creating json object from POJO object in restful web service
You can use GSon to convert json object to java object Link to refer example. Gson gson = new Gson(); //to get json object use toJson String json = gson.toJson(obj); //to get java object use fromJson MyClass obj = gson.fromJson(jsonObj, MyClass.class); or jackson is also pretty fast and easy to use

Categories : Java

Nested Object Deserialization of JSON results in an empty object
SubObjA in your example is a single object but in your class it is a collection, so JSON should look like [{"ObjA":"FOO", "SubObjA":[{ "A":0, "B":true, "C":2, "D":0.2 }], "ObjB":false, "ObjC":295, }] Note brackets around SubObjA.

Categories : C#

Android:Fetch json object set in User Agent object
I am not sure but it may be help to you. Try this one: JSONObject jObject; public JSONObject getJSONFromUrl(String url) { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputS

Categories : Android

@JsonProperty Json object inside Json object
A helpful reference for using @JsonProperty annotations in a constructor is provided by StaxMan. A simple example shown below: public class Address { private String address; private String city; private String state; private String zip; // Constructors, getters/setters } public class Location { private boolean needsRecoding; private Double longitude; private Double latitude; private Address humanAddress; public Location() { super(); } @JsonCreator public Location( @JsonProperty("needs_recoding") boolean needsRecoding, @JsonProperty("longitude") Double longitude, @JsonProperty("latitude") Double latitude, @JsonProperty("human_address") Address humanAddress) { super(); this.needs

Categories : Java

json returns [object Object] instead of actual data
An object can contain actual data, what is the problem? I suggest you take a look at the network calls from your browser using the developer console or Firebug to see what object is received. Then jQuery parses the string into an object so you can use the data.

Categories : Json

Turning my php array into [object Object] json/JavaScript
You're alerting a string, so it seems that jQuery is not recognizing your response as JSON, and it is not being parsed. Try this: $.ajax({ url : "php/resource.php", data : { node_id: node_id }, dataType : "json" }).done(function(data) { alert(data); return callback(null, data); }).fail(function() { return callback("AJAX error"); });

Categories : PHP

Serialize an object containing a child object via JSON
My Working Code Action Method [HttpPost] public JsonResult Json(AModel test) { return Json(new { Success = true }); } JQuery $.ajax({ url : "@Url.Action("Load", "MyController")", contentType : "application/json; charset=utf-8", dataType : "json", type : "POST", data : JSON.stringify({test: values}) })}).done(function (result) { //Success }).fail(function (result) { //Failed }).always(function(result) { //Always }); Models public class AModel { public string Title { get; set; } public string Text { get; set; } public BModel BModel { get; set; } } public class BModel { public string Summary { get; set; } public string Page { get; set; } } Mistakes Serialization was mising Content Ty

Categories : Asp Net Mvc

JSON object deserialize to c# object - OpenTSDB
I believe the JSON you are receiving is an array. The exception is trying to say you are converting an object[] to OpenTSDBResponse when you really want OpenTSDBResponse[]. Another way to debug this would be to look at the variable variable and see what type it is in the debugger. Of course the line that throws the exception would need to be commented out. Tackling new error It looks like DPS is not a proper JSON array. You could parse it to a dictionary since it looks like the keys will be different in each JSON call. JSON convert dictionary New class: internal class OpenTSDBResponse { [JsonProperty("metric")] public string Metric { get; set; } [JsonProperty("tags")] public Tags Tags { get; set; } [JsonProperty("aggregateTags")]

Categories : C#

Parsing a JSON object-within-an-object in javascript
I have tried below json structure var json={ "cj-api": { "products": [ { "$": { "total-matched": "231746", "records-returned": "999", "page-number": "1" }, "product": [] } ] } } now json['cj-api']['products'][0]['product'] will work

Categories : Javascript

Angularjs : how to use key of object to retrieve value of another json object
Because $scope.array (I suppose, instead of $scope.arrary) is an array, key in <div ng-repeat="(key,value) in array"> gives you the indexes starting from 0 (i.e. 0, 1, 2) instead of the alphabets (a, b, c) which you intended. One way you could handle this is to change the format of $scope.array so that you have $scope.array = [{"key":"a", "value":"value"},{"key":"b", "value":"value2"},{"key":"c", "value":"value3"}]; You can then use the keys on the second object as <div ng-repeat="a in array"> {{ secondObje[a.key] }} <br> </div> However, if you want to keep $scope.array the way it is, you can use the keys on the second object as <div ng-repeat="a in array"> <div ng-repeat="(key, value) in a"> {{ secondObje[key] }} <br>

Categories : Angularjs

DataContractJsonSerializer include object name in JSON object
Add datacontractjsonserializersettings to your constructor on DataContractDataSerializer http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializersettings.emittypeinformation.aspx Try using rootname setting in the constructor instead. http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializersettings.rootname.aspx

Categories : Json

ASP Stored Procedure Operation is not allowed when the object is closed
Your command needs a connection object, and it needs to be opened, rather than just a connection string. See http://support.microsoft.com/kb/300382 Additionally, your code will be clearer if you import the ADODB constants file, and use those (ie: http://www.4guysfromrolla.com/webtech/faq/Beginner/faq7.shtml )

Categories : SQL

extracting all data from database but "attempt to re-open an already-closed object"
You have to close your cursor in get_All_Ex_Data(), after your loop. The thing you open and close in onPreExecute and onPostExecute is the db helper. Edit : is your database helper a singleton ? You have an example of a singleton here: Using Singleton design pattern for SQLiteDatabase

Categories : Android

Visitor-Pattern vs. open/closed principle: how to add new visitable object?
It depends on precisely what job the Visitor is supposed to accomplish, but in most cases, this is what interfaces are for. Consider a SortedSet; the implementation needs to be able to compare the different objects in the set to know their ordering, but it doesn't need to understand anything else about the objects. The solution (for sorting by natural order) is to use the Comparable interface.

Categories : Java

Android - attempt to re-open an already-closed object: SQLiteQuery using loaderManager
Fixed it: @Override public void onLoadFinished(Loader cursorLoader, Cursor cursor) { if(!cursor.isClosed()){ adapter.swapCursor(cursor); } } I do have another problem now, my list does not get updated automatically...

Categories : Android

Celery and SQLAlchemy - This result object does not return rows. It has been closed automatically
All together: any advise to skip these difficulties? yes. you absolutely cannot use a Session (or any objects which are associated with that Session), or a Connection, in more than one thread simultaneously, especially with MySQL-Python whose DBAPI connections are very thread-unsafe*. You must organize your application such that each thread deals with it's own, dedicated MySQL-Python connection (and therefore SQLAlchemy Connection/ Session / objects associated with that Session) with no leakage to any other thread. Edit: alternatively, you can make use of mutexes to limit access to the Session/Connection/DBAPI connection to just one of those threads at a time, though this is less common because the high degree of locking needed tends to defeat the purpose of using multiple threads

Categories : Python

Exception:"The request was aborted: The connection was closed unexpectedly" When invoking two methods same object
I would be using the 'using' keyword around all of my IDisposables first off. Secondly looks like you are leave the StreamReaders open. Edit To answer you comment about using keyword. Instead of this: Stream str = req.GetRequestStream(); str.Write(System.Text.Encoding.ASCII.GetBytes(lgRequest), 0, lgRequest.Length); str.Close(); Write it this way: using(Stream str = req.GetRequestStream()) { str.Write(System.Text.Encoding.ASCII.GetBytes(lgRequest), 0, lgRequest.Length); } The using keyword will automatically handle all IDisplosable task for you. I just noticed something your code and why I thought you weren't closing. You are calling close and then trying to ready the lines. This is a good example of why to get into the habit of using the 'using' keyword. StreamReader reader

Categories : C#

runtime error 2467: The expression you entered refers to an object that is closed or doesnt exist
Pretty sure it should be Set objOtherTbls = Application.CreateAdditionalData() and not Set objOtherTbls = Application.CreateAdditionalData as you are calling a method.

Categories : Vba

jQuery+Edge Animate: Error only when called from click event: Object [object Object] has no method 'foundation'
I hadn't realized that Edge loads in a version of jQuery. Using jQuery's noConflict() fixed the problem: <script> $(document).foundation(); $.noConflict(); jQuery(document).ready(function($) { // Code that uses jQuery's $ can follow here. // This works as expected $('#myModal').foundation('reveal', 'open'); $("#myButton").click(function() { // This generates the error: //Uncaught TypeError: Object [object Object] has no method 'foundation' $('#myModal').foundation('reveal', 'open'); return false; }) }); </script>

Categories : Javascript

Chrome Extension, JQuery error "Uncaught TypeError: Object [object Object] has no method 'text'"
name is in your global scope, so it's actually conflicting with window.name. window.name silently converts its value to a string, which is where your error is coming from: > window.name = $('<a>') > window.name "[object Object]" > window.fooname = $('<a>') > window.fooname [<a>​</a>​] So to fix it, either wrap your code in an anonymous function to prevent things from leaking into the global scope: (function() { ... })(); Or use a different variable name. I would use the self-executing anonymous function.

Categories : Javascript

Property accessor 'Title' on object x threw the following exception:'Object reference not set to an instance of an object
public partial class Products : System.Web.UI.Page { public class Products2 { public string ItemNumber { get; set; } public string ItemDescription { get; set; } public string PrePrice { get; set; } public string Size { get; set; } } //.... Then: List<Products2> list = new List<Products2>(); foreach (DataRow dr in table.Rows) { Products2 products = new Products2(); products.ItemNumber = dr["Item #"].ToString(); products.ItemDescription = dr["Item Description"].ToString(); products.PrePrice = dr["Pre Price"].ToString(); products.Size = dr["Size"].ToString(); list.Add(products); }

Categories : Asp Net

Pass object into method, assign that object to another object, passed in object still the same object I passed in
You are adding 3 customers to the lookup with the same key (id) after the first for loop run the fetch method returns true for the rest of the for loop runs. so the name will never be set. You could try this: if( $this->identityMap->lookup($customer) ) { return $this->identityMap->get($customer); } But dont forget to implement the method "get" in the IdentityMap Class ;)

Categories : PHP

JSON.NET: Serialize json string property into json object
You need a converter to do that, here is an example: public class RawJsonConverter : JsonConverter { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteRawValue(value.ToString()); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { throw new NotImplementedException(); } public override bool CanConvert(Type objectType) { return typeof(string).IsAssignableFrom(objectType); } public override bool CanRead { get { return false; } } } Then decorate your class with it: public class Foo { public int Id; [JsonConverter(typeof(RawJsonConverter))] public string RawData; } Then, when you use:

Categories : C#

Multi object knockout mapping
You have to move your Contact function outside of the ContactGroup function. It's scope is limited within the ContactGroup function and is not able to be seen by the ko.utils.arrayMap function. Moving it outside increases the scope to the entire TechnicalViewModel. function TechnicalViewModel(jsonData){ self = this; var ContactGroups = ko.utils.arrayMap(jsonData.contactGroups, function(item) { var group = new ContactGroup(item); var contacts = ko.utils.arrayMap(item.contact, function(item) { return new Contact(item) }); group.contact(contacts) return group; }); self.contactGroups = ko.observableArray(ContactGroups); function Contact(data) { this.name = ko.observable(data.name); this.email = ko.obser

Categories : Javascript

Design DS for Multi-pattern Object
How about store K pointers for each item, indicates the next item with the same K-th variety . Then for each query, pick one variety and enumerate all the items with that variety satisfied, check if it meets other constraints and show it. Thus take an O(NK) for each query and O(1) for adding a new item, while the space is O(NK). your scenario looks just like a database, why don't you check on that.

Categories : Performance

WordPress Uncaught TypeError: Object [object Object] has no method 'live' | thickbox.js:23
If you are using jQuery version 9.1+, try adding jQuery Migrate plugin. Add following to functions.php add_action( 'admin_enqueue_scripts', 'admin_scripts' ); function admin_scripts() { wp_enqueue_script('jquery-migrate','http://code.jquery.com/jquery-migrate-1.2.1.js',array('jquery')); }

Categories : Javascript

Trying to use a jQuery file in Wordpress, which requires noConflict, but now my Object [object Object] has no method
Wrap your functions and jQuery code in this: ;(function ($) { //Code in here })(jQuery); This assigns the $ to jQuery only. Doing this prevents conflicts with other libraries/code that also use the $. Also leading this code with a ; protects your function from unclosed scripts. I wouldn't rely on the noConflict() method. <script type="text/javascript"> ;(function ($, window, document, undefined) { //You can do it like this too //Make sure to replace all your 'jQuery' referecens to '$' //jQuery.extend({}, _self.defaults, _self.options, _self.metadata) $.extend({}, _self.defaults, _self.options, _self.metadata) })(jQuery, window, document); </script>

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.