Posts

Showing posts with the label json

JSON RPC - What is the “id” for?

JSON RPC - What is the “id” for? I don't understand what the ID is for in JSON RPC. Also, how bad is it considered to not use JSON-RPC.org's standards when developing a toolkit? There seems to be some ambiguity in the JSON-RPC world. P.S. The ID I'm referring to is the id in here: {"params":["Hello","World"],"method":"hello_world","id":1} 5 Answers 5 You're not guaranteed to get your answers back in the order you asked for them; the id is to help you sort that out. Oh, in the case of asynchronous calls. That makes sense. – orokusaki Feb 5 '10 at 22:29 What if JSON-RPC over HTTP? ID seems to be useless since HTTP is designed by request-response patt...

unity c# - how to get values of list

unity c# - how to get values of list<object> I have this json: [ [ [ "Tel Aviv", "Beersheba", "Jerusalem", "Haifa" ] ], [ { "City": "Tel Aviv" }, { "City": "Beersheba" }, { "City": "Jerusalem" }, { "City": "Haifa" }, { "City": "Jerusalem" }, { "City": "Tel Aviv" }, { "City": "Haifa" }, { "City": "Beersheba" }, { "City": "Jerusalem" }, { "City": "Jerusalem" }, { "City": "Haifa" }, { "City": "Tel Aviv" }, { "City": "Tel Aviv" }, { "City": "Beershe...

Can't receive PHP object by using AJAX

Can't receive PHP object by using AJAX I can't fetch the php file from the ajax. Firstly an object is created in the PHP file, then it is converted into JSON by using json_encode() function. The problem is: when I request that PHP file from ajax, nothing is shown as an output. ('Smith' is supposed to be an output though) Here is my php file: 1.php <?php $myObj->name = "Smith"; $myObj->age = 20; $myObj->Address = "Yangon"; $myJSON = json_encode($myObj); echo "$myJSON"; ?> Here is ajax file: ajaxfile.php <p id="demo"></p> <script type="text/javascript"> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if (this.readyState == 4 && this.status == 200) { var myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.name; } }; xmlhttp.open(...

convert object to string using JSON.stringify show empty object

Image
convert object to string using JSON.stringify show empty object I'm trying to convert object to string using JSON.stringify and I get empty object console.log('typeof',typeof e,' e value is',e, 'JSON stringify is',JSON.stringify(e)) the error message when I try to print typeof object e value is Error: Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred. JSON stringify is {} @ManuallyOverridden console.log is variadic — you can pass multiple objects, which are separated by a , . – Mark Meyer Jul 1 at 6:38 console.log , It looks like e is an error object. In node, stringifying an error results in {} . Not sure how you are running your code. – Mark Meyer Jul 1 at 6:40 ...

How can cast the string to json using C#?

Image
How can cast the string to json using C#? One string like this: [["0.45842413","10"],["0.45850028","11"],["0.46092215","10"],["0.478999","133.69218728"]] after cast like this: [["Price":"0.45842413","Amount":"10"],["Price":"0.45850028","Amount":"11"],["Price":"0.46092215","Amount":"10"],["Price":"0.478999","Amount":"133.69218728"]] the question is unclear – yekanchi Jul 1 at 3:38 2 Answers 2 Your question is unclear, both strings are JSON You're basically asking how to cast from one format of JSON to another. The ...

Extracting JSON element

Extracting JSON element I have a JSON response from the website shown below. I want to print the 'value' and 'datetime' keys of data . I am not able to access these two elements in JSON response. 'value' 'datetime' data data= {"parameter_name":"Inst", "parameter_code":"WL1","data":[ {"value":3.1289999485,"datetime":"2018-07-01T00:00:00+00:00"}, {"datetime":"2018-07-01T00:30:00+00:00","value":3.1859998703}, {"value":3.33099985123,"datetime":"2018-07-01T00:45:00+00:00"}, {"datetime":"2018-07-01T01:15:00+00:00","value":3.22300004959}, {"datetime":"2018-07-01T01:45:00+00:00","value":3.32299995422}]} my code till now for element in len(data['data']): date = element['datetime'] value = element[...

Update a numeric property of a JSON object in an array

Update a numeric property of a JSON object in an array My JSON config.json : [ { "names":"Steam", "count": 1, }, { "names":"game", "count": 2, } ] I need to update count 's property in the array in c#. I tried count JObject objectproperty = JObject.Parse(File.ReadAllText(@"config.json")); but this gives me the error Newtonsoft.Json.JsonReaderException: "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1." That's not a valid json object – Mardoxx Jun 30 at 23:42 The exception message tells you the solution. Use JArray for arrays, not JObject (which is, obviously, for objects) – Camilo Terevi...

Store and retrieve interfaces in golang

Store and retrieve interfaces in golang How can we store array of different structs into some file and retrieve it back in the same format without losing its properties(methods it provides). For example: I have data struct A and struct B , both implementing a common interface X {} with some methods. struct A struct B interface X {} One options is to write both save and retrieve method to accept the interface X slice. However the problem is how to unmarshal it back in some generic way which is not tied to my Data struct. i.e., every time I add a new data struct I need not to change my save or retrieve functions to retrieve back the slice of interface X so that its methods can be used independent of data struct. Example where Unmarshaling throws error : Go PlayGround Link with a small Example 3 Answers 3 However the problem is how to unmarshal it back in some generic way which is not tied to my Data...

Parsing dynamic json in go

Parsing dynamic json in go I am trying to parse the following json structure, where the fields marked with "val1" and "val2" are constantly changing, so I cannot use a predefined struct. How could I parse this json in a way to be able to loop through every single "val"? Thank you! {"result":true,"info":{"funds":{"borrow":{"val1":"0","val2":"0"},"free":{"val1":"0","val2":"0"},"freezed":{"val1":"0","val2":"0"}}}} struct { Borrow, Free, Freezed map[string]interface{} } – ThunderCat Jun 30 at 20:09 struct { Borrow, Free, Freezed map[string]interface{} } Possible duplicate of stackoverfl...

Notice: Trying to get property 'id' of non-object in C:

<b>Notice</b>: Trying to get property 'id' of non-object in <b>C: When i tried to update or delete it give this notice <b>Notice</b>: Trying to get property 'id' of non-object in <b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>24</b><br /><br /> <b>Notice</b>: Trying to get property 'taskName' of non-object in <b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>25</b><br /> <br /> <b>Notice</b>: Trying to get property 'taskDescription' of non-object in <b>C:UsersHusam Al-MasriPhpstormProjectsTODOapitasksupdate.php</b> on line <b>26</b><br /> {"message": "task was updated."} in get and create the code worked, whats the wrong in my update code? I search in stackoverflow with the same title but i see every body has a case differe...

How to store json object to shared preferences?

How to store json object to shared preferences? I am creating an application,In my app I am getting response and displaing it in custom alert dialog, Till here it works fine, Now what I am trying to do is if user selects an item from alert dialog once, it should store it in preference so that no need of fetch the data every time. Following is my code snippet. The following response which i am getting is : { "states": [ { "id": "1", "state_slug": "agra", "statename": "Agra" }, { "id": "2", "state_slug": "andaman_and_nicobar_islands", "statename": "Andaman and Nicobar Islands" }, { "id": "3", "state_slug": "andhra_pradesh", "statename": "Andhra Pradesh...