swift – “The given data was not valid JSON.”, underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 JsonDecoder can’t decode

class NewsService { func fetchNews() throws -> [News] { let data = Data(JsonData.data1.utf8) do { return try JSONDecoder().decode(NewsResponse.self, from: data).data } catch { print(error) throw error } } } struct JsonData { static let data0 = “”” { “data”: [ { “news_url”: “https://seekingalpha.com/article/4523221-what-is-holding-back-china-stimulus”, “image_url”: “https://cdn.snapi.dev/images/v1/a/t/image-1316474363-1451807.jpg”, “title”: “What Is Holding Back China Stimulus?”, “text”: “One of … Read more

python 3.x – How to declare pydantic BaseModel in FastAPI to receive a valid json object

A client app is sending data to server using POST method. Data basically has 4 key-value pairs out of which value of the secod key is a valid json object with multiple key-value pairs in it. It currently looks like this { “name”: “string”, “content”: {{“resolution”:”1″,”symbol_type”:”stock”,”exchange”:”NSE”,”listed_exchange”:””,”symbol”:”NSE:SBIN-EQ”,”short_name”:”SBIN”,”legs”:”[{“symbol”:”SBIN”,”pro_symbol”:”SBIN”}]”,”name”:”asdwa”,”description”:””,”charts_symbols”:”{“1”:{“symbol”:”NSE:SBIN-EQ”}}”,”is_realtime”:”1″,”content”:”{“name”:”asdwa”,”layout”:”s”,”charts”:[{“panes”:[{“sources”:[{“type”:”MainSeries”,”id”:”RGTnHz”,”state”:{“style”:1,”esdShowDividends”:true,”esdShowSplits”:true,”esdShowEarnings”:true,”esdShowBreaks”:false,”esdFlagSize”:2,”showCountdown”:false,”bidAsk”:{“visible”:false,”lineStyle”:1,”lineWidth”:1,”bidLineColor”:”#2962FF”,”askLineColor”:”#EF5350″},”prePostMarket”:{“visible”:true,”lineStyle”:1,”lineWidth”:1,”preMarketColor”:”#fb8c00″,”postMarketColor”:”#2962FF”},”highLowAvgPrice”:{“highLowPriceLinesVisible”:false,”highLowPriceLabelsVisible”:false,”averageClosePriceLineVisible”:false,”averageClosePriceLabelVisible”:false},”showInDataWindow”:true,”visible”:true,”showPriceLine”:true,”priceLineWidth”:1,”priceLineColor”:””,”baseLineColor”:”#B2B5BE”,”showPrevClosePriceLine”:false,”prevClosePriceLineWidth”:1,”prevClosePriceLineColor”:”rgba( 85, 85, 85, 1)”,”minTick”:”default”,”dividendsAdjustment”:{},”sessionId”:”regular”,”sessVis”:false,”statusViewStyle”:{“fontSize”:16,”showExchange”:true,”showInterval”:true,”symbolTextSource”:”description”},”candleStyle”:{“upColor”:”#26a69a”,”downColor”:”#ef5350″,”drawWick”:true,”drawBorder”:true,”borderColor”:”#378658″,”borderUpColor”:”#26a69a”,”borderDownColor”:”#ef5350″,”wickColor”:”#737375″,”wickUpColor”:”#26a69a”,”wickDownColor”:”#ef5350″,”barColorsOnPrevClose”:false,”drawBody”:true},”hollowCandleStyle”:{“upColor”:”#26a69a”,”downColor”:”#ef5350″,”drawWick”:true,”drawBorder”:true,”borderColor”:”rgba( 55, 134, 88, 1)”,”borderUpColor”:”#26a69a”,”borderDownColor”:”#ef5350″,”wickColor”:”rgba( 115, … Read more

Sending Posix message via pipe

Sending Posix message via pipe I have the following file called helper.h, which I want to call in server and client files later. Code: #ifndef HELPER_H #include <iostream> … Read more