I want to get transaction details using Solana API with python. There are two documents for it.
1: https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
2: https://michaelhly.github.io/solana-py/rpc/api/#solana.rpc.api.Client.get_transaction
I used this code below
solana_client = Client("https://api.mainnet-beta.solana.com")
from solders.signature import Signature
sig = Signature.from_string("3NHUEPkc7a2mPkC51umAbLdNjrwoEaCXfdJ7BjHaEhYPchy5TtrCifbJqSujyZCNRuDKDfJvpN8osx9KvSWdwMp8")
solana_client.get_transaction(sig).value.block_time
and I got multiple errors
TypeError: Object of type Signature is not JSON serializable
TypeError: dict had unencodable value at keys: {params: because (list had unencodable value at index: [0: because (Object of type Signature is not JSON serializable)])}
TypeError: Could not encode to JSON
Any idea how can i handle this error?
Related
I received a JSON object via MQTT in a react.js app. I can clearly see that the power value exists but nevertheless, I get the exception from the question title. I assume I wrongly access the JSON but how should I access it?
How the JSON object looks:
Here is how I do it now:
// this is one component where I receive it
let decodedMessage = JSON.parse(message);
//power component where I am supposed to receive it
const {portside} = this.props
const power = portside.power
I am following the offical documentation here: https://flutter.dev/docs/development/data-and-backend/json#serializing-json-inline
Map<String, dynamic> user = jsonDecode(jsonString);
print('Howdy, ${user['name']}!');
print('We sent the verification link to ${user['email']}.');
When using the lint package from pub.dev I get the error:
A value of type 'dynamic' can't be assigned to a variable of type 'Map<String, dynamic>'.
Try changing the type of the variable, or casting the right-hand type to 'Map<String, dynamic>'.dartinvalid_assignment)
I see the problem that the JSON fields have to be of dynamic type, however, what is the best way to deal with the lint package in this case? Also, the extraction of the decoded fields (i.e. userName = user['name']) throws an error because of type mismatch (dynamic vs String for example).
Hi i want to make JSON readable by using loads and dumps, but i encountered this error
"TypeError: the JSON object must be str, not 'list'"
Here is my code:
parsedCoin = json.loads(coin)
print(json.dumps(parsedCoin, indent=4, sort_keys=True))
how i can solve this problem?
json.loads expects a string. json.dumps(coin) will give you a string version of coin.
I'm trying to parse JSON to an object in Dart, the documentation uses Map type to parse a JSON response.
regarding to their documentation Using Dart with JSON Web Services: Parsing JSON
,I snipped the following example:
import 'dart:convert';
main() {
String mapAsJson = '{"language":"dart"}'; // input Map of data
Map parsedMap = JSON.decode(mapAsJson);
print(parsedMap["language"]); // dart
}
I applied the same in my testApp, however it didn't work
test() {
var url = "http://localhost/wptest/wp-json/wp/v2/posts";
// call the web server asynchronously
var request = HttpRequest.getString(url).then(onDataLoaded);
}
onDataLoaded(String responseText) {
Map x = JSON.decode(responseText);
print(x['title'].toString());
}
I'm getting this error
Exception: Uncaught Error: type 'List' is not a subtype of type 'Map' of 'x'.
Stack Trace:
post.post (package:untitled8/wp/posts.dart:25:24)
onDataLoaded (http://localhost:63342/untitled8/web/index.dart:24:15)
_RootZone.runUnary (dart:async/zone.dart:1166)
_Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:494)
_Future._propagateToListeners (dart:async/future_impl.dart:577)
_Future._completeWithValue (dart:async/future_impl.dart:368)
_Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:422)
_microtaskLoop (dart:async/schedule_microtask.dart:43)
_microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
_ScheduleImmediateHelper._handleMutation (dart:html:42567)
The JSON coming from the sever need to be decoded to a json in dart and assigned to a map of type String and dynamic
The keys in the json have to String while their value pair has to be of type dynamic in other to hold any value be it an array or int or bool
Map<String,dynamic> z = Map<String,dynamic>.from(JSON.decode(responseText));
print(z.toString())
The documentation is correct.
//if JSON is an array (starts with '[' )
List<Map> x = JSON.decode(responseText);
print(x[0]['title']);
//if JSON is not an array (starts with '{' )
Map z = JSON.decode(responseText);
print(z['content']);
print(z['id']);
print(z['title']);
Restkit is mapping my date just fine to an object, but when trying to do an inverse mapping back to json i'm getting this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Invalid type in JSON write (__NSDate)'
Obviously this is an issue with the json parser for iOS, but I figured the inverse should be handled by RestKit as well. Anyone else experience this or have a solution?
In logging restkit I get this message right before:
D restkit.object_mapping:RKMappingOperation.m:920 Finished mapping operation successfully...
**EDIT:
Mapping example:
// Define media mapping
RKObjectMapping *mediaMapping = [Media getObjectMapping];
// Define Post mapping
RKObjectMapping *postMapping = [RKObjectMapping mappingForClass:[self class]];
[postMapping addAttributeMappingsFromDictionary:#{
#"post_id": #"postID",
#"userID": #"userID",
#"title": #"title",
#"favorite": #"favorite",
#"created": #"created",
#"modified": #"modified"}];
// Define relationship in the mapping between Media and Post
[postMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:#"media"
toKeyPath:#"media"
withMapping:mediaMapping]];
Discriptor example:
RKObjectMapping *entityMapping = [object getObjectMapping];
RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping
method:RKRequestMethodPOST
pathPattern:request.URL.relativePath
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
**UPDATE2:
Right from the dictionary I break point and inspected the offending value in the destination object.
[11] = #"created" : 2014-04-21 11:04:43 PDT
key __NSCFConstantString * #"created" 0x002d3818
value __NSDate * 2014-04-21 11:04:43 PDT 0x155bab10
I can see the issue, it appears to be passing the dictionary with the NSDate to [NSJSONSerialization dataWithJSONObject: options: error:] via this method, [RKSerialization dataFromObject: error;
Should RestKit not be converting the NSDate using the RKValueTransformer I have defined before passing to NSJSONSerialization?
Open issue at github can be found here.