Development tools: wechat developer tools Windows 10 system.
Function Description: This is a part of the code that uploads a picture to the server and returns the image ID and URL. I print out the result of the process and put it in the second picture.
Problem Description: I don't understand why the return value of successful upload needs to be processed with json.parse. I can't get the data directly through res.data.data.id. the developer tool will report an undefined error.
Specific introduction: according to my query data, JSON. Parse () method is generally a string when receiving server data, and converts the data into JavaScript objects. My own understanding is that according to the print result of line 861 in my second picture, I think the res.data I get is a string of data, which needs to be converted into a JSON object through json.parse before I can get data through the converted JSON object.
If my understanding is correct, I would like to ask if the back-end development can encapsulate res.data.data as a JSON object at the beginning, so that the front-end does not need the transformation steps( Because I used to get data through res.data.data, I was not sure about my understanding when I encountered this kind of error information for the first time. Thank you!
Related
I am trying to use WDIO's getLogs('browser') to capture debug info from a JS application. The debug info is in JSON format. In manual testing, i can see all the data in JSON from console. But when i utomated it in WDIO. The message returned from getLogs for that entry doesn't contain the JSON data, it only shows it as Object. The message is like 'JSapplication.js line 123 Object', so it is useless. Does anyone know how to get the data in JSON? By the way the JS application is from a third party, not editable.
I was able to grab the message, but it is not what I wanted
I want to know how to get all the data passed on the WebSocket
I alredy tryied using FireFox to see but all the data are strange unicode text and symbols (game link is https://sploop.io) is there an way to maybe decrypt it?
I also tryied using
var data= new WebSocket("usa1.sploop.io/ws")
data.onmessage = (sa)=>{console.log(sa)}
And after some actions in the game the code logged an object that didnt have any of the data...
You're already getting all the data the WebSocket is receiving. The problem is that the data is "encoded" binary data using the game's protocol. The scripts in Sploop.io know how to decode this data (and encode new data to be sent back), but since you don't "speak" that protocol, it looks like gibberish to you.
Problem aside, you can have fun and all, but trying to cheat or so isn't nice towards other players.
I have a standard Dialogflow agent, using javascript/node.js webhooks. It works perfectly well in most cases. I have recently encountered a problem which has me at a complete loss. I am currently saving some JSON-objects in conv.data to minimize the external API-calls my webhook have to make. For one specific JSON-object, fetched from an external API using node-fetch, the response I send from my side looks perfectly ordinary. I use firebase and the firebase logs do not show any error messages or any sign that there might be a problem. But I get this error in the Google Actions console:
UnparseableJsonResponse API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "Parsing terminated before end of input. 8,\\"3\\":12},\\"w ^".
And in the stackdriver logs, the received response does not start with the usual
Received response from agent with body: HTTP/1.1 200 OK Server: ... etc
Instead it starts in the middle of the external API-JSON-file
Received response from agent with body: 8,\\"3\\":12},\\"winPercentage\\":1392}}}}, ... etc
This does not happen the first time the agent responds after fetching the JSON from the external API. The second time the agent responds after fetching the JSON, everything crashes regardless of whether the information from the JSON is used by that second call, regardless of anything at all except if the JSON file is overwritten between first and second call. If the file is overwritten the program runs perfectly. So the problem is likely part of storing and/or parsing this specific JSON file. Unfortunately the API I use in this application is not a public one and due to NDAs I cannot give any access to that JSON, so I understand that it is probably impossible for you to help me. I will however give as much information about the JSON as I can, and hope for the best:
It is valid according to https://codebeautify.org/jsonvalidator and jsonlint.com
It is structured the exact same way as other JSON files from the same API which do not crash the application
It is slightly larger that other JSON files from the same API. It has around 340 000 characters, others are around 280-300 000.
All JSONs, this as well as those that work, is from a Swedish company, therefore unusual characters like å, ä and ö are likely present.
The error message is always the same, except the start of the response is in different places in the JSON file. "8,\\"3\\":12}, ...", "ostPosition\\":2 ...", "3804,\\"startPoints\\":2960 ..." are some examples.
I am extremely grateful for any and all help I might receive, even if it's just what questions I need to ask, or where I might try troubleshooting next.
I suspect the problem is that the JSON you're trying to save is larger than the buffer size they allocate for conv.data, although I can't find any documentation to say there is some specific limit.
I'd check to see where the strings you're seeing in the error header are located in the JSON and try to keep it well under that limit.
I am using python 2.7 on windows 7 with requests requests module.
I am trying to find the source of some data from a website that uses AJAX/javascript to drive events.
Here is my python post:
result = s.post(url, headers = {'referer': my_referer})
The output from this post looks like this:
{"ADATA":{"COUNT":0.0,"AITEM":[]},"WM":0.0,"CM":0.0,"PC":"","PW":"","NC":14,"RR":false,"RTIME":{"RITEM":[],"COUNT":0.0},"WC":1.0,"CC":1.0,"RW":false,"RA":false,"RC":true}
"AITEM":[] should be populated with all the data I'm after but as you see its not. Also RC: should be false. Or at least it is when I go through my browser
Note that I get "RA":true and "RC":false if I use get instead of post request. I dont know why.
Here is the corresponding post in the javascript server side:
$.getJSON (url, function(data){UpdateStuff(data);});
Disclaimer: I have been programming for about a week now.
This JSON post is in a function that receives no parameters and returns nothing as far as I can tell. data is not referenced in the function prior to the post. I dont really understand what function(data) is. UpdateStuff(data) is another function with a bunch of code that takes data and returns nothing. The code reveals some stuff about the data structure with references such as:
if (data.RA){resetAL();} else {
if (data.RR ){objAR.attr('ref','Y');}
if (data.RC ){objAC.attr('ref','Y');}
if (data.RW ){objAW.attr('ref','Y');}
Which I guess I am failing this logic gate since my data is different than what I see in a successful browser request.
and references to data.ADATA.COUNT and data.ADATA.AITEM[i] etc
I've been told this would be much simpler to write in JS but I have about 70% of this program done in python already and I've never used JS.
Any help is greatly appreciated.
i'm using phonegap in order to make an application, then i'm using CodeIgniter as an API.
To get the data, i'm using a simple $.post from jQuery to a REST URL in CodeIgniter.
$.post(DIR+trad+"/format/json", function(data){
traducciones = jQuery.parseJSON(data);
}, json);
Based upon this, i got 2 questions, because i don't know if i should do it in different post methods.
The first question is, how do i get the data in json format?
The second question is, is there any way to call the json object directly from my view (HTML) ? or i need to do it using jquery or javascript?
how do i get the data in json format?
Searching for codeigniter+json gives me Output Class which has this example:
$this->output
->set_content_type('application/json')
->set_output(json_encode(array('foo' => 'bar')));
is there any way to call the json object directly from my view (HTML)?
Generally speaking, if you are generating the JSON yourself and you want to use it in HTML, then you will just skip generating JSON and use the data directly.
Generating JSON from a view only really becomes useful if you want to make the raw data available over a network.
If you want to fetch the data over HTTP for your view, then that is a job for the Model. See How to send a GET request from PHP?. This is useful if you have two different applications. One providing a web service for the data and one providing the user facing application.
If you want to update the page with new data after it has loaded, then this is a good usecase for JSON, but you can only do that with JavaScript (or another client side programming language).
If you want to using JSON as response format, just do like
$.post(url, {
"dataType" : "json",
"success" : function(response) {
// process your response here, it will be treated as JSON object
}
});