Posts

Showing posts with the label json

Parse JSON in Swift 24hours of problems

Parse JSON in Swift 24hours of problems I am really struggling to parse a json file into my iOS app in Swift. I have a JSOn output from an SQL db. I think the formatting is wrong and the data headers are a bit ambiguous but my developer who I hired to create the process is happy with the output. Link below. So in the last 3 days I have read all of the Apple Developer materials on parsing JSON, also watched numerous tutorials which all cover pretty much the same data, and I don't know how much I have read and converted into actual projects which have all failed. I am really needing some guidance here. I have even in a desperate attempt to understand my problem from a different perspective I have looked at how it is done in other languages. This is the latest iteration: func flightData()-> [[String: String]]{ let url = URL(string: "http://35.237.114.234/api/index.php?uid=Bx7faf08A9fYJ7bZCNMUX9EzxYN2") guard let jsonFileURL = Bundle.main.url(forResource: "jso...

convert json string to variables

convert json string to variables maybe my question is a bit unreasonable, but what's wrong i ask. I have a simple script like below <?php $r['code'] = 200; $r['result'] = "hello world"; $r['down'][0] = "first"; $r['down'][1] = "second"; echo json_encode($r, JSON_PRETTY_PRINT); ?> and the results from the script are { "code": 200, "result": "hello world", "down": [ "first", "second" ] } as seen above, that variables can be converted to json by using json_encode, and to my question, can we change json back into variables? for example Before { "code": 200, "result": "hello world", "down": [ "first", "second" ] } After <?php $r['code'] = 200; $r['result'] = "hello world"; $r['down'][0] = "first"; $r['down'][1] = ...

Python/Django: Populating Model Form Fields with values from Imported JSON file

Python/Django: Populating Model Form Fields with values from Imported JSON file I have a model form that saves all form field inputs to the backend database as one entry. I also have a JSON file that contains multiple JSON objects whose fields corresponds to the model form field. This JSON file is being uploaded via FileField in the model. Ultimately, I want to be able to upload a JSON file with the multiple JSON objects into my model form and populate the fields with the corresponding values from the uploaded JSON file. Each JSON object will be a single entry to my database and they can have null values for at least one field. Ideally, I would like to be able to choose which JSON object (from the uploaded JSON file) gets loaded to my model form fields to eventually be saved in my database. How would I go about implementing this? docs.python.org/3/tutorial/… – Ignacio Vazquez-Abrams Jun 29 at 23:50 ...

How to get a JSON unique field's name and deeply nested child field's value in Golang?

How to get a JSON unique field's name and deeply nested child field's value in Golang? I have a json file that looks like this { "links": { "uniqueurl_1": { "a": { "b": [ "stuff" ], "I": { "want": { "to": "morestuff", "go": { "in": { "here": { "and": "array", "itis": { "very": "string", "deep": "stringIwant" } } } } } } } } } } And I want to get the uniqueurl_1 (that is always different for each link), and I also want to get the "deep" field's value ("stringIwant") uniqueurl_1 I know if it's ...

SWIFT model for parsing JSON

SWIFT model for parsing JSON I need to parse the data of JSON. For this I will use the protocol Codable . The json received looks like this (this is the part that interests me): ( { description = mySecondGist; files = { "gistfile1.txt" = { filename = "gistfile1.txt"; language = Text; "raw_url" = "https://gist.githubusercontent.com/VladimirKhuraskin/9ca2362c09cebcc16bd74f51f267231a/raw/74caacd3ad3eedb369a07b926327d2ef37e3eefc/gistfile1.txt"; size = 17; type = "text/plain"; }; }; } ) I made this model: struct Gists: Codable { var description: String? var files: DetailGist? private enum CodingKeys: String, CodingKey { case description case files } } struct DetailGist: Codable { var filename: String? var rawUrl: String? private enum FileCodingK...

React Native display simple Json Data

React Native display simple Json Data I am trying to create a simple page, in which I want to display the data i get from the Json file. Unfortunately I get "Invariant Violation: Objects are not valid as a React child (found: object with keys {ts, trend, baro, temp, hum, wind, rain, et, forecast, sun}). If you meant to render a collection of children, use an array instead." So it loads the Json but I cant display the data. If tried various methods, but couldnt solve it. App.js import React from 'react' import { AppRegistry, StyleSheet, FlatList, Text, View, Alert, ActivityIndicator, Platform} from 'react-native' export default class Planner extends React.Component { constructor(props) { super(props); this.state = { isLoading: true } } componentDidMount() { return fetch('url') .then((response) => response.json()) .then((responseJson) => { this.setState({ isLoading: false, ...

What is the best method to seeding a Node / MongoDB application?

What is the best method to seeding a Node / MongoDB application? So, I'm new to the MEAN stack, and I've hit a wall trying to seed MongoDB. I'm using Mongoose to communicate with the database, and there's a bunch of documentation suggesting I should be able to seed using populated JSON files. What I've tried: node-mongo-seed ; Pretty straight forward, but consistently throws errors on the end of arrays. (Perhaps the missing bson module is at fault?) { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version Seeding files from directory /Users/Antwisted/code/wdi/MEAN/seeds ---------------------- Seeding collection locations err = [SyntaxError: /Users/Antwisted/code/wdi/MEAN/seeds/locations.json: Unexpected token {] mongoose-seed ; Also pretty straight forward, basically puts the JSON objects into a variable before exporting to the database. Promising, but... more ...

how do i use JSON response with Ajax

how do i use JSON response with Ajax I am trying to use the JSON response from my Ajax request, but no matter what I try i cannot get this to work so would like some help please. My code for the ajax request is below <html> <head> <title>QuizMaster</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> http://jquery-3.1.0.min.js function player(x){ var player = x; $.ajax({ url:"gameDb.php", type: "GET", data: {"request":player}, dataType: "json", success: function(data){ console.log(data); var obj = JSON.parse(data); console.log(obj[1].player1); //console.log(data['player1']);//undefined //console.log(data[player[0]]); } }); } $(document).ready(function(){ $('#button input').click(function(){ var x = this.id; player(x); }); }); With this i get the reponse ` player1.php:18 Uncaught ReferenceError...

How to represent a table structure in jsonapi

Image
How to represent a table structure in jsonapi Have the following problem. We are implementing a REST API very much based on JsonApi specification. We are importing table structured files. Where: - part of the row is the metadata of Object1 - column header is the link to an external Object2 - cell value is the 'expression' of the relationship between Object1 and Object2. For example: You have biological sample (Object2) and run experiment to see if a specific mutation (Object 1) is available to that sample. The cell value can have different values which specifically state that a mutation for that sample is present, partially present or non present. How using JSONAPI we would be able to represent such relationship. In which object the cell value should be saved? Object1? The relationship object? UPD: Forgot to mention. If we use only the "green" part of the row (metadata), we would be able to create unique objects. Which could be reused across files and linked to new ob...

JSON return null 'meiter'

JSON return null 'meiter' I have a function that displays the select id 'technicien' and he showed his name from table user and there 'metier' techniciens_tables Schema::create('techniciens', function (Blueprint $table) { $table->increments('id'); $table->boolean('actif')->default(1); $table->float('moyenne_avis')->nullable(); $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->datetime('deleted_at')->nullable(); $table->timestamps(); }); metier_tables Schema::create('metiers', function (Blueprint $table) { $table->increments('id'); $table->string('libelle_metier'); $table->datetime('deleted_at')->nullable(); $table->timestamps(); }); users_table Schema::create('users', function (Bl...

How to sort data coming from the API by date in Angular 4

How to sort data coming from the API by date in Angular 4 This is the JSON data i am fetching from POSTMAN. I want it to be ordered in a nearest to todays date. I tried many angular pipes but unfortunately nothings working. Any help would be great. I want to sort the date by the "broadcastOn" field. Thanks in advance. [ { "messageId": "09ca0609-bde7-4360-9d3f-04d6878f874c", "broadcastOn": "2018-02-08T11:06:05.000Z", "message": "{"title":"Server Side Test 2","text":"Different Message again","image":"https://api.adorable.io/avatars/285/abott@adorable.png","url":"https://www.google.co.in"}" }, { "messageId": "0a5b4d0c-051e-4955-bd33-4d40c65ce8f7", "broadcastOn": "2018-02-08T10:36:27.000Z", "message": "{"title":"Broadc...

Dynamic column table in anguler js + Type scripts

Image
Dynamic column table in anguler js + Type scripts I want to create following dynamic column table using anguler js. According to the my requirement, column sets such as fruit, vegetables can change dynamically according to the data sets. I want to load data from json file. ex: [ { "clusterID":"1", "storeCode": "S2HK", "storeName": "store 1", "Vegetables": { "Ordered":"272", "Delivery":"250", "FR":"70%", "Gap":"22" }, "Fruit": { "Ordered":"300", "Delivery":"250", "FR":"60%", "Gap":"50" } }, { "clusterID":"1", "storeCode": "SCCC", "storeName": "store 2", "Vegetables": { "Ordered":"500...

How to Remove Whole Index of List in a JSON

How to Remove Whole Index of List in a JSON I have a JSON Values Like This. { "CHEQUE":[ { "Cheque_No":"1", "Cheque_Date":"2018-05-30", "Cheque_Amount":"10000", "Bank_Name":"ICICI" }, { "Cheque_No":"2", "Cheque_Date":"2018-05-30", "Cheque_Amount":"20000", "Bank_Name":"ICICI" }, { "Cheque_No":"2", "Cheque_Date":"2018-05-30", "Cheque_Amount":"20000", "Bank_Name":"SBI" } ] }' How can i Remove Entire Index of 2 in a CHEQUE list using the search key SBI for Bank name?. I need to Do this is in Mysql Stored Procedure without Store Values in DB. This is what I have tried: CREATE DEFINER = root @ PROCEDURE SP_TEST( IN ls_json JSON, OUT Message VARCHAR(1000) ) BEGIN SELECT JSON_REMOVE( ...

Springboot - empty get rest response

Image
Springboot - empty get rest response I am building a simple get rest call from MySQL database, the problem is that it returns an empty object. The call itself is takes in an email (I know this is not the best approach), here is my code: Entity: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_id") private int id; private String email; private String password; private String firstName; private String userName; private String lastName; private boolean active; @Temporal(TemporalType.DATE) private Date createDate; @Temporal(TemporalType.DATE) private Date updateDate; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id")) private Collection<Role> roles; // constructor // get and setter } Reposi...